#include "UsrAI.h"
#include<set>
#include<vector>
#include <iostream>
#include<unordered_map>
//时代
#define CIVILIZATION_STONEAGE 1
#define CIVILIZATION_TOOLAGE 2
using namespace std;
tagGame tagUsrGame;
ins UsrIns;
//等级记录
static int Wood_Level=1;
static int Stone_Level=1;
static int Farm_Level=1;
static int Tool_Level=1;
static int Gold_Level=1;
static int Defense_Infantry_Level=1;
static int Defense_Archer_Level=1;
static int Defense_Rider_Level=1;
//管理系统
//农民目标资源、建筑映射
unordered_map<int,int>SN_to_Sort;
// 农民状态记录数组
vector<tagFarmer>idleFarmer;               // 存储闲置的农民
vector<tagFarmer>fishingFarmer;            // 存储捕鱼的农民
vector<tagFarmer>cuttingFarmer;            // 存储砍树的农民
vector<tagFarmer>buildingHouseFarmer;      // 存储建造房子的农民
vector<tagFarmer>huntingGZFarmer;          // 存储捕猎羚羊的农民
vector<tagFarmer>huntingELFarmer;          // 存储捕猎大象的农民
vector<tagFarmer>miningFarmer;             // 存储采矿的农民
vector<tagFarmer>goldFarmer;               // 存储采金的农民
vector<tagFarmer>buildingDockFarmer;
vector<tagFarmer>buildingCenterFarmer;
vector<tagFarmer>buildingFarmFarmer;
vector<tagFarmer>buildingMarketFarmer;
vector<tagFarmer>buildingGranaryFarmer;
void UsrAI::arrangeFarmer(tagInfo info)
{
    //建立资源映射
    for(tagResource myResource :info.resources)
        SN_to_Sort[myResource.SN] =myResource.Type;
    //建立建筑映射
    for(tagBuilding myBuilding :info.buildings)
        SN_to_Sort[myBuilding.SN] =myBuilding.Type;
    // 遍历并统计农民情况
    for(tagFarmer myFarmer:info.farmers) {
        if(myFarmer.FarmerSort == 0){
                 if(myFarmer.NowState == HUMAN_STATE_IDLE) idleFarmer.push_back(myFarmer);
                 if(myFarmer.NowState == HUMAN_STATE_WORKING){
                     // 状态对应
                     int Type = SN_to_Sort[myFarmer.WorkObjectSN];
                     if(Type == RESOURCE_TREE) cuttingFarmer.push_back(myFarmer);
                     if(Type == RESOURCE_FISH) fishingFarmer.push_back(myFarmer);
                     if(Type == BUILDING_HOME) buildingHouseFarmer.push_back(myFarmer);
                     if(Type == BUILDING_DOCK) buildingDockFarmer.push_back(myFarmer);
                     if(Type == BUILDING_CENTER) buildingCenterFarmer.push_back(myFarmer);
                     if(Type == BUILDING_FARM) buildingFarmFarmer.push_back(myFarmer);
                     if(Type == BUILDING_MARKET) buildingMarketFarmer.push_back(myFarmer);
                     if(Type == BUILDING_GRANARY) buildingGranaryFarmer.push_back(myFarmer);
                     if(Type == RESOURCE_GAZELLE) huntingGZFarmer.push_back(myFarmer);
                     if(Type == RESOURCE_ELEPHANT) huntingELFarmer.push_back(myFarmer);
                     if(Type == RESOURCE_STONE) miningFarmer.push_back(myFarmer);
                     if(Type == RESOURCE_GOLD)goldFarmer.push_back(myFarmer);
                 }
         }
    }
}
//敌方大陆上的农民数组
vector<tagFarmer>Boat_farmer;
vector<tagFarmer>on_E_land_farmer;
vector<tagFarmer>e_idleFarmer;               // 存储闲置的农民
vector<tagFarmer>e_cuttingFarmer;            // 存储砍树的农民
vector<tagFarmer>e_miningFarmer;             // 存储采矿的农民
vector<tagFarmer>exploringFarmer;
vector<tagFarmer>buildingStockFarmer;
vector<tagFarmer>buildingArmycampFarmer;
vector<tagFarmer>buildingStableFarmer;
vector<tagFarmer>buildingRangeFarmer;
vector<tagFarmer>buildingArrowtowerFarmer;
void UsrAI::arrangeE_farmer(tagInfo info)
{
    if(on_E_land_farmer.size()==0)return;
    // 遍历并统计农民情况
    tagFarmer t;
    for(tagFarmer myFarmer:on_E_land_farmer)
    {
        if(myFarmer.FarmerSort == 0)
        {
            // 将闲置农民加入数组
            if(myFarmer.NowState == HUMAN_STATE_IDLE)
            {
                e_idleFarmer.push_back(myFarmer);
                for(int i=0;i<idleFarmer.size();i++)
                {
                    if(myFarmer.SN==idleFarmer[i].SN)
                    {
                        t=idleFarmer[idleFarmer.size()-1];
                        idleFarmer[idleFarmer.size()-1]=idleFarmer[i];
                        idleFarmer[i]=t;
                        idleFarmer.pop_back();
                        break;
                    }
                }
            }
            if(myFarmer.NowState == HUMAN_STATE_WALKING)exploringFarmer.push_back(myFarmer);
            if(myFarmer.NowState == HUMAN_STATE_WORKING)
            {
                // 状态对应
                int Type = SN_to_Sort[myFarmer.WorkObjectSN];
                if(Type == RESOURCE_TREE)e_cuttingFarmer.push_back(myFarmer);
                if(Type == RESOURCE_STONE)e_miningFarmer.push_back(myFarmer);
                if(Type == BUILDING_STOCK)buildingStockFarmer.push_back(myFarmer);
                if(Type == BUILDING_ARMYCAMP)buildingArmycampFarmer.push_back(myFarmer);
                if(Type == BUILDING_STABLE)buildingStableFarmer.push_back(myFarmer);
                if(Type == BUILDING_RANGE)buildingRangeFarmer.push_back(myFarmer);
                if(Type == BUILDING_ARROWTOWER)buildingArrowtowerFarmer.push_back(myFarmer);
             }
        }
    }
}
//渔船状态数组
vector<tagFarmer>idlesailingBoat;
vector<tagFarmer>fishingsailingBoat;
vector<tagFarmer>exploringsailingBoat;
void UsrAI::arrangeSailingBoat(tagInfo info)
{
    for(tagFarmer myFarmer:info.farmers)
    {
        if(myFarmer.FarmerSort==2)
        {
            if(myFarmer.NowState==HUMAN_STATE_IDLE)idlesailingBoat.push_back(myFarmer);
            else if(myFarmer.NowState==HUMAN_STATE_WORKING)fishingsailingBoat.push_back(myFarmer);
            else exploringsailingBoat.push_back(myFarmer);
        }
    }
}
//房子状态数组
vector<tagBuilding>idleHome;            //空闲房子
vector<tagBuilding>bornHome;            //建造中房子
void UsrAI::arrangeHome(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_HOME)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornHome.push_back(myBuilding);
            else idleHome.push_back(myBuilding);
        }
    }
}
//市镇中心状态数组
vector<tagBuilding>idleCenter;
vector<tagBuilding>bornCenter;
vector<tagBuilding>createHumanCenter;
vector<tagBuilding>upgradeCenter;
void UsrAI::arrangeCenter(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_CENTER)
        {
            if(myBuilding.Project==BUILDING_CENTER_CREATEFARMER)createHumanCenter.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_CENTER_UPGRADE)upgradeCenter.push_back(myBuilding);
            else if(myBuilding.Percent>0&&myBuilding.Percent<100)bornCenter.push_back(myBuilding);
            else idleCenter.push_back(myBuilding);
        }
    }
}
//船坞状态数组
vector<tagBuilding>idleDock;
vector<tagBuilding>createSailingDock;
vector<tagBuilding>createWoodBoatDock;
vector<tagBuilding>createShipDock;
vector<tagBuilding>bornDock;
void UsrAI::arrangeDock(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_DOCK)
        {
            if(myBuilding.Project==BUILDING_DOCK_CREATE_SAILING)createSailingDock.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_DOCK_CREATE_WOOD_BOAT)createWoodBoatDock.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_DOCK_CREATE_SHIP)createShipDock.push_back(myBuilding);
            else if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornDock.push_back(myBuilding);
            else idleDock.push_back(myBuilding);
        }
    }
}
//谷仓状态数组
vector<tagBuilding>idleGranary;
vector<tagBuilding>arrowtowerGranary;
vector<tagBuilding>bornGranary;
void UsrAI::arrangeGranary(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_GRANARY)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornGranary.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_GRANARY_ARROWTOWER)arrowtowerGranary.push_back(myBuilding);
            else idleGranary.push_back(myBuilding);
        }
    }
}
//市场状态数组
vector<tagBuilding>idleMarket;
vector<tagBuilding>bornMarket;
vector<tagBuilding>upgradeWoodMarket;
vector<tagBuilding>upgradeStoneMarket;
vector<tagBuilding>upgradeFarmMarket;
vector<tagBuilding>upgradeGoldMarket;
void UsrAI::arrangeMarket(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_MARKET)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornMarket.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_MARKET_WOOD_UPGRADE)upgradeWoodMarket.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_MARKET_STONE_UPGRADE)upgradeStoneMarket.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_MARKET_FARM_UPGRADE)upgradeFarmMarket.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_MARKET_GOLD_UPGRADE)upgradeGoldMarket.push_back(myBuilding);
            else idleMarket.push_back(myBuilding);
        }
    }
}
//农田状态数组
vector<tagBuilding>idleFarm;
vector<tagBuilding>bornFarm;
void UsrAI::arrangeFarm(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_FARM)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornFarm.push_back(myBuilding);
            else idleFarm.push_back(myBuilding);
        }
    }
}
//仓库状态数组
vector<tagBuilding>idleStock;
vector<tagBuilding>bornStock;
vector<tagBuilding>upgradeToolStock;
vector<tagBuilding>upgradeDefenseInfantryStock;
vector<tagBuilding>upgradeDefenseArcherStock;
vector<tagBuilding>upgradeDefenseRiderStock;
void UsrAI::arrangeStock(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_STOCK)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornStock.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_STOCK_UPGRADE_USETOOL)upgradeToolStock.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_STOCK_UPGRADE_DEFENSE_INFANTRY)upgradeDefenseInfantryStock.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_STOCK_UPGRADE_DEFENSE_ARCHER)upgradeDefenseArcherStock.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_STOCK_UPGRADE_DEFENSE_RIDER)upgradeDefenseRiderStock.push_back(myBuilding);
            else idleStock.push_back(myBuilding);
        }
    }
}
//海洋探索部署
//战船状态数组
vector<tagArmy>idleShip;
vector<tagArmy>exploringShip;
vector<tagArmy>attackingShip;
void UsrAI::arrangeShip(tagInfo info)
{
    for(tagArmy myArmy:info.armies)
    {
        if(myArmy.Sort==AT_SHIP)
        {
            if(myArmy.NowState==HUMAN_STATE_IDLE)idleShip.push_back(myArmy);
            else if(myArmy.WorkObjectSN!=0)attackingShip.push_back(myArmy);
            else exploringShip.push_back(myArmy);
        }
    }
}
//运输船状态数组
vector<tagFarmer>idleWoodBoat;
vector<tagFarmer>movingWoodBoat;
void UsrAI::arrangeWoodBoat(tagInfo info)
{
    for(tagFarmer myFarmer:info.farmers)
    {
        if(myFarmer.FarmerSort==1)
        {
            if(myFarmer.NowState==HUMAN_STATE_IDLE)idleWoodBoat.push_back(myFarmer);
            else movingWoodBoat.push_back(myFarmer);
        }
    }
}
//战斗策略编组
//军营状态数组
vector<tagBuilding>idleArmycamp;
vector<tagBuilding>bornArmycamp;
vector<tagBuilding>createClubmanArmycamp;
vector<tagBuilding>createSlingerArmycamp;
vector<tagBuilding>upgradeClubmanArmycamp;
void UsrAI::arrangeArmycamp(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_ARMYCAMP)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornArmycamp.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_ARMYCAMP_CREATE_CLUBMAN)createClubmanArmycamp.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_ARMYCAMP_CREATE_SLINGER)createSlingerArmycamp.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_ARMYCAMP_UPGRADE_CLUBMAN)upgradeClubmanArmycamp.push_back(myBuilding);
            else idleArmycamp.push_back(myBuilding);
        }
    }
}
//靶场状态数组
vector<tagBuilding>idleRange;
vector<tagBuilding>bornRange;
vector<tagBuilding>createBowmanRange;
void UsrAI::arrangeRange(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_RANGE)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornRange.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_RANGE_CREATE_BOWMAN)createBowmanRange.push_back(myBuilding);
            else idleRange.push_back(myBuilding);
        }
    }
}
//马厩状态数组
vector<tagBuilding>idleStable;
vector<tagBuilding>bornStable;
vector<tagBuilding>createScoutStable;
void UsrAI::arrangeStable(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_STABLE)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornStable.push_back(myBuilding);
            else if(myBuilding.Project==BUILDING_STABLE_CREATE_SCOUT)createScoutStable.push_back(myBuilding);
            else idleStable.push_back(myBuilding);
        }
    }
}
//箭塔状态数组
vector<tagBuilding>idleArrowtower;
vector<tagBuilding>bornArrowtower;
vector<tagBuilding>attackingArrowtower;
void UsrAI::arrangeArrowtower(tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_ARROWTOWER)
        {
            if(myBuilding.Percent>=0&&myBuilding.Percent<100)bornArrowtower.push_back(myBuilding);
            else if(myBuilding.ProjectPercent>0&&myBuilding.ProjectPercent<100)attackingArrowtower.push_back(myBuilding);
            else idleArrowtower.push_back(myBuilding);
        }
    }
}
//投石兵、斧头兵、弓箭手、骑兵状态数组
vector<tagArmy>idleSlinger;
vector<tagArmy>movingSlinger;
vector<tagArmy>attackingSlinger;
//
vector<tagArmy>idleSwordsman;
vector<tagArmy>movingSwordsman;
vector<tagArmy>attackingSwordsman;
//
vector<tagArmy>idleBowman;
vector<tagArmy>movingBowman;
vector<tagArmy>attackingBowman;
//
vector<tagArmy>idleScout;
vector<tagArmy>movingScout;
vector<tagArmy>attackingScout;
//
vector<tagArmy>idleclubman;
vector<tagArmy>movingclubman;
vector<tagArmy>attackingclubman;
void UsrAI::arrangeArmy_on_land(tagInfo info)
{
    for(tagArmy myArmy:info.armies)
    {
        if(myArmy.Sort==AT_SLINGER)
        {
            if(myArmy.NowState==HUMAN_STATE_IDLE)idleSlinger.push_back(myArmy);
            else if(myArmy.WorkObjectSN!=0)attackingSlinger.push_back(myArmy);
            else movingSlinger.push_back(myArmy);
        }
        if(myArmy.Sort==AT_SWORDSMAN)
        {
            if(myArmy.NowState==HUMAN_STATE_IDLE)idleSwordsman.push_back(myArmy);
            else if(myArmy.WorkObjectSN!=0)attackingSwordsman.push_back(myArmy);
            else movingSwordsman.push_back(myArmy);
        }
        if(myArmy.Sort==AT_BOWMAN)
        {
            if(myArmy.NowState==HUMAN_STATE_IDLE)idleBowman.push_back(myArmy);
            else if(myArmy.WorkObjectSN!=0)attackingBowman.push_back(myArmy);
            else movingBowman.push_back(myArmy);
        }
        if(myArmy.Sort==AT_SCOUT)
        {
            if(myArmy.NowState==HUMAN_STATE_IDLE)idleScout.push_back(myArmy);
            else if(myArmy.WorkObjectSN!=0)attackingScout.push_back(myArmy);
            else movingScout.push_back(myArmy);
        }
        if(myArmy.Sort==AT_CLUBMAN)
        {
            if(myArmy.NowState==HUMAN_STATE_IDLE)idleclubman.push_back(myArmy);
            else if(myArmy.WorkObjectSN!=0)attackingclubman.push_back(myArmy);
            else movingclubman.push_back(myArmy);
        }
    }
}
//命令函数集合
//实时地图
void UsrAI::createMAP(char map[][128],tagInfo info)
{
    for(int i=0;i<128;i++)
    {
        for(int j=0;j<128;j++)
        {
            if((*info.theMap)[i][j].type==MAPPATTERN_GRASS)map[i][j]='+0';
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN)map[i][j]='-';
        }
    }
    int x=0,y=0;
    for(int i=0;i<info.resources.size();i++)
    {
        x=info.resources[i].BlockDR;
        y=info.resources[i].BlockUR;
        if(info.resources[i].Type==RESOURCE_GOLD)
            map[x][y]='w';
        else map[x][y]='+A';
    }
    for(int i=0;i<info.buildings.size();i++)
    {
        x=info.buildings[i].BlockDR;
        y=info.buildings[i].BlockUR;
        //if(info.buildings[i].Tpye==BUILDING_CENTER)map[x][y]='#';
        map[x][y]='+a';
    }
    for(int i=0;i<info.enemy_buildings.size();i++)
    {
        x=info.enemy_buildings[i].BlockDR;
        y=info.enemy_buildings[i].BlockUR;
        map[x][y]='+a';
    }
    for(int i=0;i<info.farmers.size();i++)
    {
        x=info.farmers[i].BlockDR;
        y=info.farmers[i].BlockUR;
        map[x][y]='*';
    }
    for(int i=0;i<info.enemy_farmers.size();i++)
    {
        x=info.enemy_farmers[i].BlockDR;
        y=info.enemy_farmers[i].BlockUR;
        map[x][y]='*';
    }
    for(int i=0;i<info.armies.size();i++)
    {
        x=info.armies[i].BlockDR;
        y=info.armies[i].BlockUR;
        map[x][y]='*';
    }
    for(int i=0;i<info.enemy_armies.size();i++)
    {
        x=info.enemy_armies[i].BlockDR;
        y=info.enemy_armies[i].BlockUR;
        map[x][y]='*';
    }
}
void UsrAI::show_MAP(char map[][128])
{
    for(int i=0;i<128;i++)
    {
        for(int j=0;j<128;j++)cout<<map[i][j]<<" ";
        cout<<endl;
    }
}

//寻找资源
int UsrAI::findResource(tagFarmer farmer, int Type,tagInfo info)
{
    int ox=0,oy=0;
    double d=0xffffffff;
    double t=0;
    int obSN=0;
    for(tagResource myResource:info.resources)
    {
        if(myResource.Type==Type)
        {
            ox=abs(farmer.BlockDR-myResource.BlockDR);
            oy=abs(farmer.BlockUR-myResource.BlockUR);
            t=sqrt(ox*ox+oy*oy);
            if(t<d)
            {
                d=t;
                obSN=myResource.SN;
            }
        }
    }
    return obSN;
}

//村民砍树
void UsrAI::farmer_to_tree(int k,tagInfo info)
{
     // 安排不超过k个农民砍树
    while(idleFarmer.size() && cuttingFarmer.size()<k)
    {
        HumanAction(idleFarmer[idleFarmer.size()-1].SN,findResource(idleFarmer[idleFarmer.size()-1], RESOURCE_TREE,info));
        DebugText("安排农民" + QString::number(idleFarmer[idleFarmer.size()-1].SN) + "砍树");
        cuttingFarmer.push_back(idleFarmer[idleFarmer.size()-1]);            // 加入砍树农民数组
        idleFarmer.pop_back();
    }
}
void UsrAI::farmer_to_tree2(int k,tagInfo info)
{
    while(e_idleFarmer.size()&&e_cuttingFarmer.size()<k)
    {
        HumanAction(e_idleFarmer[e_idleFarmer.size()-1].SN,findResource(e_idleFarmer[e_idleFarmer.size()-1], RESOURCE_TREE,info));
        DebugText("安排农民" + QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN) + "砍树");
        e_cuttingFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);            // 加入砍树农民数组
        idleFarmer.pop_back();
    }
}
//寻找合适的造房陆地
static int begin_x = 0, begin_y = 0;
static int center_x = 0, center_y = 0;
// 从市镇中心开始查找2*2的空地，通过引用返回空地左下角坐标x,y
bool UsrAI::find_block(int& x,int& y,tagInfo info)
{
    for (int i = begin_x; i < 127; i++)
    {
        for (int j = begin_y + 1; j < 127; j++)
        {
            if (i + 1 < 128 && j + 1 < 128)
            {
                // 检查四个位置是否都是陆地
                if ((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS)
                {
                    cout << "找到陆地: " << i << ", " << j << endl;

                    // 检查高度是否相等（平地）
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height)
                    {
                        // 找到符合条件的2*2空地，返回左下角坐标
                        x = i,begin_x = i;
                        y = j,begin_y = j;
                        return true; // 返回1表示成功找到
                    }
                }
            }
        }
    }
    return false; // 返回0表示未找到合适的空地
}
bool UsrAI::idleblock(int x,int y,tagInfo info)
{
    for(tagBuilding myBuilding:info.buildings)
    {
        if(myBuilding.Type==BUILDING_HOME)
        {
            if((myBuilding.BlockDR==x&&myBuilding.BlockUR==y)||
               (myBuilding.BlockDR+1==x&&myBuilding.BlockUR==y)||
               (myBuilding.BlockDR==x&&myBuilding.BlockUR+1==y)||
               (myBuilding.BlockDR+1==x&&myBuilding.BlockUR+1==y))
                return false;
        }
        else
        {
            if((myBuilding.BlockDR==x&&myBuilding.BlockUR==y)||
              (myBuilding.BlockDR+1==x&&myBuilding.BlockUR==y)||
              (myBuilding.BlockDR==x&&myBuilding.BlockUR+1==y)||
              (myBuilding.BlockDR+1==x&&myBuilding.BlockUR+1==y)||
              (myBuilding.BlockDR==x&&myBuilding.BlockUR+2==y)||
              (myBuilding.BlockDR+1==x&&myBuilding.BlockUR+2==y)||
              (myBuilding.BlockDR+2==x&&myBuilding.BlockUR==y)||
              (myBuilding.BlockDR+2==x&&myBuilding.BlockUR+1==y)||
              (myBuilding.BlockDR+2==x&&myBuilding.BlockUR+2==y))
                return false;
        }
    }
    for(tagResource myResource:info.resources)
    {
        if(myResource.Type==RESOURCE_TREE||myResource.Type==RESOURCE_GAZELLE)
        {
            if(myResource.BlockDR==x&&myResource.BlockUR==y)
                return false;
        }
        else
        {
            if((myResource.BlockDR==x&&myResource.BlockUR==y)||
              (myResource.BlockDR+1==x&&myResource.BlockUR==y)||
              (myResource.BlockDR==x&&myResource.BlockUR+1==y)||
              (myResource.BlockDR+1==x&&myResource.BlockUR+1==y))
                return false;
        }
    }
    for(tagFarmer myFarmer:info.farmers)
    {
        if(myFarmer.BlockDR==x&&myFarmer.BlockUR==y)
            return false;
    }
    for(tagArmy myArmy:info.armies)
    {
        if(myArmy.BlockDR==x&&myArmy.BlockUR==y)
            return false;
    }
    return true;
}
//村民造房(使用前判断木材是否足够）
void UsrAI::farmer_to_home(tagInfo info)
{
    //安排建造1个房子
    // 初始化市镇中心坐标
    if (center_x == 0 && center_y == 0)
    {
         for (tagBuilding& building : info.buildings)
         {
             if (building.Type == BUILDING_CENTER)
             {
                  center_x = building.BlockDR;
                  center_y = building.BlockUR;
             }
         }
     }
    // 初始化搜索的起始坐标
    if (begin_x == 0 && begin_y == 0)
    {
        begin_x = center_x-2;
        begin_y = center_y-4;
    }
    int x=0,y=0;
    if(find_block(x,y,info)&&idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info))
    {
        HumanBuild(idleFarmer[idleFarmer.size()-1].SN,BUILDING_HOME,x,y);
        DebugText("安排农民" + QString::number(idleFarmer[idleFarmer.size()-1].SN) + "造房");
        buildingHouseFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
        idleFarmer.pop_back();
    }
}

//寻找合适的海洋
static int DockX=0;
static int DockY=0;
//坐标要求：
//合法，修建位置在海上且相邻地块为陆地
//距离村民出发点最近
// 从该当前位置开始查找2*2的空地
bool UsrAI::find_sea(tagInfo info)
{
    int bx=DockX,by=DockY;
    int x=0,y=0;
    int ox=0,oy=0;
    double d=0xffffffff;
    double t=0;
    for (int i =15; i < 128; i++) {
        for (int j =27; j < 128; j++) {
            if (i + 2 < 128 && j + 2 < 128) {
                // 检查四个位置是否都是海洋,是否靠近陆地，是否已探索
                if (idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                    (*info.theMap)[i][j].type==MAPPATTERN_OCEAN &&
                    (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN &&
                    (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN &&
                    (*info.theMap)[i+1][j+1].type==MAPPATTERN_OCEAN &&
                    ((*info.theMap)[i+2][j].type==MAPPATTERN_GRASS &&
                     (*info.theMap)[i+2][j+1].type==MAPPATTERN_GRASS ||
                    ((*info.theMap)[i-1][j].type==MAPPATTERN_GRASS &&
                     (*info.theMap)[i-1][j+1].type==MAPPATTERN_GRASS)||
                    ((*info.theMap)[i][j-1].type==MAPPATTERN_GRASS &&
                     (*info.theMap)[i+1][j-1].type==MAPPATTERN_GRASS)||
                    ((*info.theMap)[i][j+2].type==MAPPATTERN_GRASS &&
                     (*info.theMap)[i+1][j+2].type==MAPPATTERN_GRASS))) {
                    if(idleDock.size()+createSailingDock.size()+createShipDock.size()+createWoodBoatDock.size()+bornDock.size()==0)
                    {
                        ox=abs(center_x-i);
                        oy=abs(center_y-j);
                    }
                    else
                    {
                        ox=abs(bx-i);
                        oy=abs(by-j);
                    }
                    t=sqrt(ox*ox+oy*oy);
                    if(t<d)
                    {
                        // 找到符合条件的2*2空地，更新左下角坐标
                        x=i,DockX=x;
                        y=j,DockY=y;
                        d=t;
                    }
                }
            }
        }
    }
    if(DockX!=bx||DockY!=by)
    {
        DebugText("找到合适船坞位置:" + QString::number(DockX) + "," + QString::number(DockY));
        return true; // 返回1表示成功找到
    }
    return false; // 返回0表示未找到合适的空地
}
//村民造船坞
void UsrAI::farmer_to_dock(tagInfo info)
{
    if(idleFarmer.size()==0)return;
    if(find_sea(info))
    {
        HumanBuild(idleFarmer[idleFarmer.size()-1].SN,BUILDING_DOCK,DockX,DockY);
        DebugText("安排农民" + QString::number(idleFarmer[idleFarmer.size()-1].SN) + "造船坞");
        buildingDockFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
        idleFarmer.pop_back();
    }
}
//确定3*3大小的空地
static int start_x=0,start_y=0;
bool UsrAI::find_block3(int& x,int& y,tagInfo info)
{
    for (int i = start_x; i < 128; i++)
    {
        for (int j = start_y; j < 128; j++)
        {
            if (i + 2 < 128 && j + 2 < 128)
            {
                // 检查9个位置是否都是陆地
                if ((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS&&idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                        idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    // 检查高度是否相等（平地）
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        x = i,start_x = i;
                        y = j,start_y = j+1;
                        return true; // 返回1表示成功找到
                    }
                }
            }
        }
    }
    return false; // 返回0表示未找到合适的空地
}
bool UsrAI::find_block3_2(int& x,int& y,tagInfo info)
{
    for (int i = start_x; i < 128; i++)
    {
        for (int j = start_y; j > 0; j--)
        {
            if (i + 2 < 128 && j + 2 >0)
            {
                // 检查9个位置是否都是陆地
                if ((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS&&idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                        idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    // 检查高度是否相等（平地）
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        x = i,start_x = i;
                        y = j,start_y = j-1;
                        return true; // 返回1表示成功找到
                    }
                }
            }
        }
    }
    return false; // 返回0表示未找到合适的空地
}
bool UsrAI::find_block3_3(int& x,int& y,tagInfo info)
{
    for (int i = start_x; i >0; i--)
    {
        for (int j = start_y; j > 0; j--)
        {
            if (i+2>0 && j+2>0)
            {
                // 检查9个位置是否都是陆地
                if ((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS&&idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                        idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    // 检查高度是否相等（平地）
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        x = i,start_x = i;
                        y = j,start_y = j-1;
                        return true; // 返回1表示成功找到
                    }
                }
            }
        }
    }
    return false; // 返回0表示未找到合适的空地
}
bool UsrAI::find_block3_4(int& x,int& y,tagInfo info)
{
    for (int i = start_x; i > 0; i--)
    {
        for (int j = start_y; j < 128; j++)
        {
            if (i + 2 > 0 && j + 2 <128)
            {
                // 检查9个位置是否都是陆地
                if ((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS &&
                    (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS&&idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
                        idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
                {
                    // 检查高度是否相等（平地）
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        x = i,start_x = i;
                        y = j,start_y = j+1;
                        return true; // 返回1表示成功找到
                    }
                }
            }
        }
    }
    return false; // 返回0表示未找到合适的空地
}
//村民造谷仓
void UsrAI::farmer_to_granary(tagInfo info)
{
    int x=0,y=0;
    if(idleFarmer.size()==0)return;
    if(find_block3(x,y,info)&&
       idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
       idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
    {
        HumanBuild(idleFarmer[idleFarmer.size()-1].SN,BUILDING_GRANARY,x,y);
        DebugText("安排农民" + QString::number(idleFarmer[idleFarmer.size()-1].SN) + "造谷仓");
        buildingGranaryFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
        idleFarmer.pop_back();
    }
}
//寻找渔场
int UsrAI::findFish(tagFarmer farmer, tagInfo info)
{
    int ox=0,oy=0;
    int x=0,y=0;
    double d=0xffffffff;
    double t=0;
    int obSN=0;
    for(tagResource myResource:info.resources)
    {
        x=myResource.BlockDR;
        y=myResource.BlockUR;
        if(myResource.Type==RESOURCE_FISH &&
          ((*info.theMap)[x-1][y].type==MAPPATTERN_GRASS&&
           (*info.theMap)[x-1][y+1].type==MAPPATTERN_GRASS||
          ((*info.theMap)[x][y-1].type==MAPPATTERN_GRASS&&
           (*info.theMap)[x+1][y-1].type==MAPPATTERN_GRASS)||
          ((*info.theMap)[x+2][y].type==MAPPATTERN_GRASS&&
           (*info.theMap)[x+2][y+1].type==MAPPATTERN_GRASS)||
          ((*info.theMap)[x][y+2].type==MAPPATTERN_GRASS&&
           (*info.theMap)[x+1][y+2].type==MAPPATTERN_GRASS)))
        {
            ox=abs(farmer.BlockDR-myResource.BlockDR);
            oy=abs(farmer.BlockUR-myResource.BlockUR);
            t=sqrt(ox*ox+oy*oy);
            if(t<d)
            {
                d=t;
                obSN=myResource.SN;
                //DebugText("找到渔场，坐标：("+QString::number(x)+","+QString::number(y)+")");
            }
        }
    }
    if(obSN!=0)return obSN;
    return -1;
}
//安排不超过k个村民捕鱼
void UsrAI::farmer_to_fish(tagInfo info,int k)
{
    while(idleFarmer.size() && fishingFarmer.size()<k) {
        HumanAction(idleFarmer[idleFarmer.size()-1].SN, findFish(idleFarmer[idleFarmer.size()-1],info));
        DebugText("安排农民"+QString::number(idleFarmer[idleFarmer.size()-1].SN)+"捕鱼");
        fishingFarmer.push_back(idleFarmer[idleFarmer.size()-1]);               // 加入捕鱼农民数组
        idleFarmer.pop_back();
    }
}
//单个村民捕猎不超过k只羚羊
void UsrAI::farmer_hunt_GZ(tagInfo info,int k)
{
    static int n=0;
    if(!idleFarmer.size()||n==k)return;
    for(tagResource resource:info.resources)
    {
        if(resource.Type==RESOURCE_GAZELLE)
        {
            HumanAction(idleFarmer[idleFarmer.size()-1].SN,resource.SN);
            DebugText("安排农民" + QString::number(idleFarmer[idleFarmer.size()-1].SN) + "捕猎羚羊");
            huntingGZFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
            idleFarmer.pop_back();
            n++;
            break;
        }
    }
}
//村民捕猎大象
static tagResource el;
static bool hunt=true;
static tagFarmer hunter;
void UsrAI::farmer_hunt_EL(int k,tagInfo info)
{
    double t;
    double d=0xffffffff;
    int x,y;
    if(huntingELFarmer.size()<k)
    {
        if(hunt)
        {
            for(tagResource resource:info.resources)
            {
                if(resource.Type==RESOURCE_ELEPHANT)
                {
                    hunter=idleFarmer[idleFarmer.size()-1];
                    x=resource.BlockDR,y=resource.BlockUR;
                    t=sqrt((hunter.BlockDR-x)*(hunter.BlockDR-x)+(hunter.BlockUR-y)*(hunter.BlockUR-y));
                    if(t<d)
                    {
                        d=t;
                        el=resource;
                    }
                }
            }
            hunt=false;
            if((*info.theMap)[el.BlockDR+3][el.BlockUR+3].type==MAPPATTERN_GRASS&&idleblock(el.BlockDR+3,el.BlockUR+3,info))
                HumanMove(hunter.SN,(el.BlockDR+3)*BLOCKSIDELENGTH,(el.BlockUR+3)*BLOCKSIDELENGTH);
            if((*info.theMap)[el.BlockDR-3][el.BlockUR+3].type==MAPPATTERN_GRASS&&idleblock(el.BlockDR-3,el.BlockUR+3,info))
                HumanMove(hunter.SN,(el.BlockDR-3)*BLOCKSIDELENGTH,(el.BlockUR+3)*BLOCKSIDELENGTH);
            if((*info.theMap)[el.BlockDR+3][el.BlockUR-3].type==MAPPATTERN_GRASS&&idleblock(el.BlockDR+3,el.BlockUR-3,info))
                HumanMove(hunter.SN,(el.BlockDR+3)*BLOCKSIDELENGTH,(el.BlockUR-3)*BLOCKSIDELENGTH);
            if((*info.theMap)[el.BlockDR-3][el.BlockUR-3].type==MAPPATTERN_GRASS&&idleblock(el.BlockDR-3,el.BlockUR-3,info))
                HumanMove(hunter.SN,(el.BlockDR-3)*BLOCKSIDELENGTH,(el.BlockUR-3)*BLOCKSIDELENGTH);
        }
        if(bornDock.size()&&bornDock[bornDock.size()-1].Percent>0&&hunt==false)
            HumanAction(hunter.SN,el.SN);
        if(idleFarmer[idleFarmer.size()-1].SN==hunter.SN)
        {
            huntingELFarmer.push_back(hunter);
            idleFarmer.pop_back();
        }
    }
}
void UsrAI::farmer_hunt_EL2(int k,tagInfo info)
{
    if(huntingELFarmer.size()<k)
    {
        HumanAction(idleFarmer[idleFarmer.size()-1].SN,el.SN);
        huntingELFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
        idleFarmer.pop_back();
    }
}
//k条渔船捕鱼（规定：所有渔船集体出航）
void UsrAI::sailing_to_fish(int k,tagInfo info)
{
    int n=0;
    while(n<k)
    {
        HumanAction(idlesailingBoat[idlesailingBoat.size()-1].SN,findResource(idlesailingBoat[idlesailingBoat.size()-1],RESOURCE_FISH,info));
        fishingsailingBoat.push_back(idlesailingBoat[idlesailingBoat.size()-1]);
        idlesailingBoat.pop_back();
        n++;
    }
}

//升级时代后：
//stage2:
//安排k个村民建1个市场
// 从农田规划区外开始查找3*3的空地，通过引用返回空地左下角坐标x,y
bool UsrAI::find_Market_block(int& x,int& y,tagInfo info)
{
    for (int j = center_y+10; j < 128; j++)
    {
        for (int i = center_x-10; i < 128; i++)
        {
            if (i + 2 < 128 && j + 2 < 128)
            {
                // 检查9个位置是否都是陆地
                if ((*info.theMap)[i][j].type == MAPPATTERN_GRASS && idleblock(i,j,info)&&
                    (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS && idleblock(i+1,j,info)&&
                    (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS && idleblock(i,j+1,info)&&
                    (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS && idleblock(i+1,j+1,info)&&
                    (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS && idleblock(i+2,j,info)&&
                    (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS && idleblock(i+2,j+1,info)&&
                    (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS && idleblock(i,j+2,info)&&
                    (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS && idleblock(i+1,j+2,info)&&
                    (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS && idleblock(i+2,j+2,info)&&idleblock(i+3,j,info)&&idleblock(i,j+3,info)&&idleblock(i-1,j,info)&&idleblock(i,j-1,info))
                {
                    cout << "找到陆地: " << i << ", " << j << endl;

                    // 检查高度是否相等（平地）
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        x = i;
                        y = j;
                        return true; // 返回1表示成功找到
                    }
                }
            }
        }
    }
    return false; // 返回0表示未找到合适的空地
}
void UsrAI::farmer_to_market(tagInfo info)
{
    int x=0,y=0;
    if(find_Market_block(x,y,info)&&idleFarmer.size())
    {
        DebugText("市场坐标：("+QString::number(x)+","+QString::number(y)+")");
        HumanBuild(idleFarmer[idleFarmer.size()-1].SN,BUILDING_MARKET,x,y);
        DebugText("安排农民"+QString::number(idleFarmer[idleFarmer.size()-1].SN)+"修建市场");
        buildingMarketFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
        idleFarmer.pop_back();
    }
}
//在市镇中心四周建造农田，规划造9个
static int Start_x=0,Start_y=0;
bool UsrAI::farm_block(int &x,int &y,tagInfo info)
{
    //从左下角开始
    for (int i = Start_x+3; i < 128; i++)
    {
        for (int j = Start_y; j < 128; j++)
        {
            if (i + 2 < 128 && j + 2 < 128)
            {
                // 检查9个位置是否都是陆地
                if ((*info.theMap)[i][j].type == MAPPATTERN_GRASS && idleblock(i,j,info)&&
                    (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS && idleblock(i+1,j,info)&&
                    (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS && idleblock(i,j+1,info)&&
                    (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS && idleblock(i+1,j+1,info)&&
                    (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS && idleblock(i+2,j,info)&&
                    (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS && idleblock(i+2,j+1,info)&&
                    (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS && idleblock(i,j+2,info)&&
                    (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS && idleblock(i+1,j+2,info)&&
                    (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS && idleblock(i+2,j+2,info))
                {
                    cout << "找到陆地: " << i << ", " << j << endl;

                    // 检查高度是否相等（平地）
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                            // 找到符合条件的3*3空地，返回左下角坐标
                            Start_x=i,Start_y=j;
                            x=i;
                            y=j;
                            DebugText("找到农田空地：("+QString::number(i)+","+QString::number(j)+")");
                            return true; // 返回1表示成功找到
                    }
                }
            }
        }
    }
    return false; // 返回0表示未找到合适的空地
}
void UsrAI::farmer_to_farm(tagInfo info)
{
    int x=0,y=0;
    if(farm_block(x,y,info))
    {
        HumanBuild(idleFarmer[idleFarmer.size()-1].SN,BUILDING_FARM,x,y);
        DebugText("安排农民"+QString::number(idleFarmer[idleFarmer.size()-1].SN)+"建造农田");
        buildingFarmFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
        idleFarmer.pop_back();
    }
}
//村民挖矿
void UsrAI::farmer_to_stone(int k,tagInfo info)
{
   // 安排不超过k个农民挖矿
   while(idleFarmer.size() && miningFarmer.size()<k) {
       HumanAction(idleFarmer[idleFarmer.size()-1].SN,findResource(idleFarmer[idleFarmer.size()-1], RESOURCE_STONE,info));
       DebugText("安排农民" + QString::number(idleFarmer[idleFarmer.size()-1].SN) + "挖矿");
       miningFarmer.push_back(idleFarmer[idleFarmer.size()-1]);            // 加入砍树农民数组
       idleFarmer.pop_back();
   }
}
//海战准备：
//n个船坞各自同时生产n只战船
void UsrAI::Dock_to_ship(int n,tagInfo info)
{
    int i=0;
    //tips:使用前判断船坞树木、木材条件是否满足
    while(i<n)
    {
        BuildingAction(idleDock[idleDock.size()-1].SN,BUILDING_DOCK_CREATE_SHIP);
        DebugText("安排船坞"+QString::number(idleDock[idleDock.size()-1].SN)+"建造战船");
        createShipDock.push_back(idleDock[idleDock.size()-1]);
        idleDock.pop_back();
        i++;
    }
}
//战船探索海洋，并寻找敌方大陆
//1.判断己方大陆在地图的哪个角，敌方在对角
int UsrAI::find_enemy(int &x,int &y)
{
    int t=0;
    if(center_x<63&&center_y<63)x=1,y=1,t=1;
    else if(center_x<63&&center_y>63&&center_y<127)x=1,y=126,t=2;
    else if(center_x>63&&center_x<127&&center_y>63&&center_y<127)x=126,y=126,t=3;
    else x=126,y=1,t=4;
    DebugText("我方在"+QString::number(t)+"号角");
    return t;
}
//2.找到初始沿海对角点
static int x_ocean=0,y_ocean=0;
static int branch=0;
void UsrAI::find_begin_sea(tagInfo info)
{
    int x=0,y=0;
    branch=find_enemy(x,y);
    switch (branch) {
    case 1:
        for(int i=center_x-5,j=center_y-5;i<127,j<127;i++,j++)
        {
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN&&(*info.theMap)[i][j+2].type==MAPPATTERN_OCEAN&&
                idleblock(i,j,info))
                x_ocean=i,y_ocean=j;
        }
        DebugText("找到初始沿海对角点:("+QString::number(x_ocean)+","+QString::number(y_ocean)+")");
        break;
    case 2:
        for(int i=DockX-3,j=DockY+3;i<127,j>0;i++,j--)
        {
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN&&(*info.theMap)[i+2][j].type==MAPPATTERN_OCEAN&&
                idleblock(i,j,info))
                x_ocean=i,y_ocean=j;
        }
        DebugText("找到初始沿海对角点:("+QString::number(x_ocean)+","+QString::number(y_ocean)+")");
        break;
    case 3:
        for(int i=x-1,j=y-1;i>0,j>0;i--,j--)
        {
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN&&(*info.theMap)[i-2][j].type==MAPPATTERN_OCEAN&&
                idleblock(i,j,info))
                x_ocean=i,y_ocean=j;
        }
        DebugText("找到初始沿海对角点:("+QString::number(x_ocean)+","+QString::number(y_ocean)+")");
        break;
    default:
        for(int i=x-1,j=y+1;i>0,j<127;i--,j++)
        {
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&(*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN&&(*info.theMap)[i-2][j].type==MAPPATTERN_OCEAN&&
                idleblock(i,j,info))
                x_ocean=i,y_ocean=j;
        }
        DebugText("找到初始沿海对角点:("+QString::number(x_ocean)+","+QString::number(y_ocean)+")");
        break;
    }
}
//判断是否出现敌人，并集体进攻
bool UsrAI::is_enemy_ship(tagInfo info)
{
    for(tagArmy enemyarmy:info.enemy_armies)
    {
        if(enemyarmy.Sort==AT_SHIP)
        {
            HumanAction(idleShip[idleShip.size()-1].SN,enemyarmy.SN);
            DebugText("派战船"+QString::number(idleShip[idleShip.size()-1].SN)+"攻打敌方战船"+QString::number(enemyarmy.SN));
            attackingShip.push_back(idleShip[idleShip.size()-1]);
            idleShip.pop_back();
            return true;
        }
    }
    return false;
}
//3.分2块区域巡逻，寻找敌方战船，同时船坞持续造战船补给（此过程在主程序中实现）
static int e_x1=0,e_y1=0;
static int e_x2=0,e_y2=0;
//6只探索一边
void UsrAI::ship_find_enemy1(tagInfo info)
{
    switch (branch) {
    case 1:
        //发现敌人
        if(is_enemy_ship(info));
        //未发现敌人
        else
        {
            if(e_x1==0&&e_y1==0)
            {
                e_x1=x_ocean;
                e_y1=y_ocean;
            }
                for(int i=e_x1,j=e_y1;i<127,j<127;i++,j++)
                {
                    if((*info.theMap)[e_x1][e_y1].type==MAPPATTERN_UNKNOWN)
                    {
                        HumanMove(idleShip[idleShip.size()-1].SN,(e_x1-1)*BLOCKSIDELENGTH,(e_y1)*BLOCKSIDELENGTH);
                        exploringShip.push_back(idleShip[idleShip.size()-1]);
                        idleShip.pop_back();
                        return;
                    }
                    if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
                       (*info.theMap)[i+1][j].type!=MAPPATTERN_GRASS&&
                       (*info.theMap)[i-1][j].type!=MAPPATTERN_GRASS&&
                       (*info.theMap)[i][j+1].type!=MAPPATTERN_GRASS&&
                       (*info.theMap)[i][j-1].type!=MAPPATTERN_GRASS)
                    {
                        HumanMove(idleShip[idleShip.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                        e_x1=i+1;
                        e_y1=j+1;
                        exploringShip.push_back(idleShip[idleShip.size()-1]);
                        idleShip.pop_back();
                    }
                }
        }
        break;
    case 2:
        //发现敌人
        if(is_enemy_ship(info));
        //未发现敌人
        else
        {
            if(e_x1==0&&e_y1==0)
            {
                e_x1=x_ocean+2;
                e_y1=y_ocean;
            }
            for(int i=e_x1,j=e_y1;i<127,j>0;i++,j--)
            {
                if((*info.theMap)[e_x1][e_y1].type==MAPPATTERN_UNKNOWN)
                {
                    HumanMove(idleShip[idleShip.size()-1].SN,(e_x1)*BLOCKSIDELENGTH,(e_y1+1)*BLOCKSIDELENGTH);
                    exploringShip.push_back(idleShip[idleShip.size()-1]);
                    idleShip.pop_back();
                    return;
                }
                if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
                   (*info.theMap)[i+1][j].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i-1][j].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j-1].type!=MAPPATTERN_GRASS)
                {
                    HumanMove(idleShip[idleShip.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    e_x1=i;
                    e_y1=j-1;
                    exploringShip.push_back(idleShip[idleShip.size()-1]);
                    idleShip.pop_back();
                }
            }
        }
        break;
    case 3:
        //发现敌人
        if(is_enemy_ship(info));
        //未发现敌人
        else
        {
            if(e_x1==0&&e_y1==0)
            {
                e_x1=x_ocean-2;
                e_y1=y_ocean;
            }
            for(int i=e_x1,j=e_y1;i>0,j>0;i--,j--)
            {
                if((*info.theMap)[e_x1][e_y1].type==MAPPATTERN_UNKNOWN)
                {
                    HumanMove(idleShip[idleShip.size()-1].SN,(e_x1+1)*BLOCKSIDELENGTH,(e_y1)*BLOCKSIDELENGTH);
                    exploringShip.push_back(idleShip[idleShip.size()-1]);
                    idleShip.pop_back();
                    return;
                }
                if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
                   (*info.theMap)[i+1][j].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i-1][j].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j-1].type!=MAPPATTERN_GRASS)
                {
                    DebugText("("+QString::number(i)+","+QString::number(j)+")");
                    HumanMove(idleShip[idleShip.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    e_x1=i-2;
                    e_y1=j-1;
                    exploringShip.push_back(idleShip[idleShip.size()-1]);
                    idleShip.pop_back();
                }
            }
        }
        break;
    default:
        //发现敌人
        if(is_enemy_ship(info));
        //未发现敌人
        else
        {
            if(e_x1==0&&e_y1==0)
            {
                e_x1=x_ocean;
                e_y1=y_ocean;
            }
            for(int i=e_x1,j=e_y1;i>0,j<127;i--,j++)
            {
                if((*info.theMap)[e_x1][e_y1].type==MAPPATTERN_UNKNOWN)
                {
                    HumanMove(idleShip[idleShip.size()-1].SN,(e_x1+1)*BLOCKSIDELENGTH,(e_y1-1)*BLOCKSIDELENGTH);
                    exploringShip.push_back(idleShip[idleShip.size()-1]);
                    idleShip.pop_back();
                    return;
                }
                if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
                   (*info.theMap)[i+1][j].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i-1][j].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type!=MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j-1].type!=MAPPATTERN_GRASS)
                {
                    DebugText("("+QString::number(i)+","+QString::number(j)+")");
                    HumanMove(idleShip[idleShip.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    e_x1=i-2;
                    e_y1=j+1;
                    exploringShip.push_back(idleShip[idleShip.size()-1]);
                    idleShip.pop_back();
                }
            }
        }
        break;
    }
}
void UsrAI::ship_find_enemy2(tagInfo info)
{
    if(is_enemy_ship(info))return;
    double d=0xffffffff;
    double t=0;
    int x,y;
    for(int i=0;i<128;i++)
    {
        for(int j=0;j<128;j++)
        {

            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&i!=idleShip[idleShip.size()-1].BlockDR&&j!=idleShip[idleShip.size()-1].BlockUR)
            {
                t=sqrt((i-idleShip[idleShip.size()-1].BlockDR)*(i-idleShip[idleShip.size()-1].BlockDR)+(j-idleShip[idleShip.size()-1].BlockUR)*(j-idleShip[idleShip.size()-1].BlockUR));
                if(t<d)
                {
                    d=t;
                    x=i;
                    y=j;
                }
            }
        }
    }
    if(d==0xffffffff)return;
    HumanMove(idleShip[idleShip.size()-1].SN,x*BLOCKSIDELENGTH,y*BLOCKSIDELENGTH);
    exploringShip.push_back(idleShip[idleShip.size()-1]);
    idleShip.pop_back();
    return;
}
void UsrAI::sailing_explore(tagInfo info)
{
    double d=0xffffffff;
    double t=0;
    int x,y;
    for(int i=0;i<128;i++)
    {
        for(int j=0;j<128;j++)
        {

            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)
               &&i!=idlesailingBoat[idlesailingBoat.size()-1].BlockDR&&j!=idlesailingBoat[idlesailingBoat.size()-1].BlockUR)
            {
                t=sqrt((i-idlesailingBoat[idlesailingBoat.size()-1].BlockDR)*(i-idlesailingBoat[idlesailingBoat.size()-1].BlockDR)+(j-idlesailingBoat[idlesailingBoat.size()-1].BlockUR)*(j-idlesailingBoat[idlesailingBoat.size()-1].BlockUR));
                if(t<d)
                {
                    d=t;
                    x=i;
                    y=j;
                }
            }
        }
    }
    if(d==0xffffffff)return;
    HumanMove(idlesailingBoat[idlesailingBoat.size()-1].SN,x*BLOCKSIDELENGTH,y*BLOCKSIDELENGTH);
    exploringsailingBoat.push_back(idlesailingBoat[idlesailingBoat.size()-1]);
    idlesailingBoat.pop_back();
    return;
}
//确定登陆细节坐标
static int land_X1=0,land_Y1=0;
bool UsrAI::no_forest(int x,int y,tagInfo info)
{
    for(int i=x-5;i<=x+5;i++)
    {
        for(int j=y-5;j<=y+5;j++)
        {
            for(tagResource myResource:info.resources)
            {
                if(myResource.Type==RESOURCE_TREE)
                {
                    if(myResource.BlockDR==i&&myResource.BlockUR==j)
                        return false;
                }
            }
        }
    }
    return true;
}
void UsrAI::decide_land1(tagInfo info)
{
    switch (branch) {
    case 1:
        for(int i=126;i>60;i--)
        {
            for(int j=126;j>55;j--)
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
              (((*info.theMap)[i+1][j].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN)||
              ((*info.theMap)[i-1][j].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN)||
              ((*info.theMap)[i][j+1].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN)||
              ((*info.theMap)[i][j-1].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN))&&
               no_forest(i,j,info))
            {
                land_X1=i,land_Y1=j;
                DebugText("确定登陆坐标：("+QString::number(land_X1)+","+QString::number(land_Y1)+")");
                return;
            }
        }
        break;
    case 2:
        if(is_enemy_ship(info));
        for(int i=x_ocean;i<128;i++)
        {
            for(int j=y_ocean;j>0;j--)
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_GRASS||
               (*info.theMap)[i-1][j].type==MAPPATTERN_GRASS||
               (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS||
               (*info.theMap)[i][j-1].type==MAPPATTERN_GRASS)&&
               no_forest(i,j,info))
            {
                land_X1=i,land_Y1=j;
                DebugText("确定登陆坐标：("+QString::number(land_X1)+","+QString::number(land_Y1)+")");
                return;
            }
        }
        break;
    case 3:
        if(is_enemy_ship(info));
        for(int i=1;i<63;i++)
        {
            for(int j=1;j<63;j++)
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_GRASS||
               (*info.theMap)[i-1][j].type==MAPPATTERN_GRASS||
               (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS||
               (*info.theMap)[i][j-1].type==MAPPATTERN_GRASS)&&
               no_forest(i,j,info))
            {
                land_X1=i,land_Y1=j;
                DebugText("确定登陆坐标：("+QString::number(land_X1)+","+QString::number(land_Y1)+")");
                return;
            }
        }
        break;
    default:
        if(is_enemy_ship(info));
        for(int i=1;i<65;i++)
        {
            for(int j=126;j>60;j--)
            if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_GRASS||
               (*info.theMap)[i-1][j].type==MAPPATTERN_GRASS||
               (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS||
               (*info.theMap)[i][j-1].type==MAPPATTERN_GRASS)&&
               no_forest(i,j,info))
            {
                land_X1=i,land_Y1=j;
                DebugText("确定登陆坐标：("+QString::number(land_X1)+","+QString::number(land_Y1)+")");
                return;
            }
        }
        break;
    }
}
//扫清敌人后，安排运输船运输村民
//安排k个村民登上运输船
void UsrAI::push_Boat_farmer(tagInfo info)
{
    switch (branch) {
    case 1:
        for(tagFarmer myfarmer:info.farmers)
        {
            if(myfarmer.FarmerSort==0)
            {
                if(myfarmer.BlockUR>53)
                    on_E_land_farmer.push_back(myfarmer);
            }
        }
        break;
    case 2:
        for(tagFarmer myfarmer:info.farmers)
        {
            if(myfarmer.FarmerSort==0)
            {
                if(myfarmer.BlockUR<70)
                    on_E_land_farmer.push_back(myfarmer);
            }
        }
        break;
    case 3:
        for(tagFarmer myfarmer:info.farmers)
        {
            if(myfarmer.FarmerSort==0)
            {
                if(myfarmer.BlockDR<63)
                    on_E_land_farmer.push_back(myfarmer);
            }
        }
        break;
    default:
        for(tagFarmer myfarmer:info.farmers)
        {
            if(myfarmer.FarmerSort==0)
            {
                if(myfarmer.BlockDR<70&&myfarmer.BlockUR>55)
                    on_E_land_farmer.push_back(myfarmer);
            }
        }
        break;
    }
}
void UsrAI::farmer_to_WoodBoat(tagInfo info)
{
    if(movingWoodBoat.size())
    {
        HumanAction(idleFarmer[idleFarmer.size()-1].SN,movingWoodBoat[movingWoodBoat.size()-1].SN);
        DebugText("安排村民"+QString::number(idleFarmer[idleFarmer.size()-1].SN)+"登上运输船"+QString::number(movingWoodBoat[movingWoodBoat.size()-1].SN));
    }
    else
    {
        HumanAction(idleFarmer[idleFarmer.size()-1].SN,idleWoodBoat[idleWoodBoat.size()-1].SN);
        DebugText("安排村民"+QString::number(idleFarmer[idleFarmer.size()-1].SN)+"登上运输船"+QString::number(idleWoodBoat[idleWoodBoat.size()-1].SN));
    }
    Boat_farmer.push_back(idleFarmer[idleFarmer.size()-1]);
    idleFarmer.pop_back();
}
//检查村民是否已登船
bool UsrAI::farmer_on_boat(tagInfo info)
{
    if(Boat_farmer.size()==0)return true;
    for(tagFarmer onboat:Boat_farmer)
    {
        for(int i=0;i<info.farmers.size();i++)
        {
            if(onboat.SN==info.farmers[i].SN)
            {
                return false;
            }
        }
    }
    return true;
}
//检查村民是否登陆
bool UsrAI::farmer_to_land(int k,tagInfo info)
{
    vector<bool>flags;
    for(tagFarmer onboat:Boat_farmer)
    {
        for(int i=0;i<info.farmers.size();i++)
        {
            if(onboat.SN==info.farmers[i].SN)
            {
                flags.push_back(true);
                break;
            }
        }
    }
    if(flags.size()==Boat_farmer.size()&&Boat_farmer.size()>=k)return true;
    return false;
}
//stage3
//村民建造仓库
static bool bg=true;
void UsrAI::sort_E_idlefarmer(tagInfo info)
{
    tagFarmer t;
    if(e_idleFarmer.size()==0)return;
    int x=e_idleFarmer[e_idleFarmer.size()-1].BlockDR;
    int y=e_idleFarmer[e_idleFarmer.size()-1].BlockUR;
    if((idleblock(x+1,y,info)&&(*info.theMap)[x+1][y].type==MAPPATTERN_GRASS)||
       (idleblock(x-1,y,info)&&(*info.theMap)[x-1][y].type==MAPPATTERN_GRASS)||
       (idleblock(x,y+1,info)&&(*info.theMap)[x][y+1].type==MAPPATTERN_GRASS)||
       (idleblock(x,y-1,info)&&(*info.theMap)[x][y-1].type==MAPPATTERN_GRASS))
        return;
    for(int i=0;i<e_idleFarmer.size();i++)
    {
        x=e_idleFarmer[i].BlockDR;
        y=e_idleFarmer[i].BlockUR;
        if((idleblock(x+1,y,info)&&(*info.theMap)[x+1][y].type==MAPPATTERN_GRASS)||
           (idleblock(x-1,y,info)&&(*info.theMap)[x-1][y].type==MAPPATTERN_GRASS)||
           (idleblock(x,y+1,info)&&(*info.theMap)[x][y+1].type==MAPPATTERN_GRASS)||
           (idleblock(x,y-1,info)&&(*info.theMap)[x][y-1].type==MAPPATTERN_GRASS))
        {
            t=e_idleFarmer[e_idleFarmer.size()-1];
            e_idleFarmer[e_idleFarmer.size()-1]=e_idleFarmer[i];
            e_idleFarmer[i]=t;
            return;
        }
    }
}
void UsrAI::farmer_to_stock(tagInfo info)
{
    int x=0,y=0;
    switch (branch) {
    case 1:
        if(start_x<63||start_y<63)
        {
            start_x=63,start_y=63;
        }
        if(find_block3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info)&&
          (*info.theMap)[x-1][y].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x][y-1].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x+3][y].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x][y+3].type!=MAPPATTERN_OCEAN)
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
            buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    case 2:
        for(int i=land_X1+20;i>0;i--)
        {
            for(int j=land_Y1+20;j>0;j--)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+2].type==MAPPATTERN_GRASS&&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height==height&&
                        (*info.theMap)[i][j+1].height==height&&
                        (*info.theMap)[i+1][j+1].height==height&&
                        (*info.theMap)[i+2][j].height==height&&
                        (*info.theMap)[i][j+2].height==height&&
                        (*info.theMap)[i+1][j+2].height==height&&
                        (*info.theMap)[i+2][j+1].height==height&&
                        (*info.theMap)[i+2][j+2].height==height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                        buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        break;
    case 3:
        if(start_x>63||start_y>63)
        {
            start_x=63,start_y=50;
        }
        if(find_block3_4(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info)&&
          (*info.theMap)[x-1][y].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x][y-1].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x+3][y].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x][y+3].type!=MAPPATTERN_OCEAN)
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
            buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    default:
        for(int j=land_Y1-20;j<128;j++)
        {
            for(int i=land_X1+20;i>0;i--)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+2].type==MAPPATTERN_GRASS&&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height==height&&
                        (*info.theMap)[i][j+1].height==height&&
                        (*info.theMap)[i+1][j+1].height==height&&
                        (*info.theMap)[i+2][j].height==height&&
                        (*info.theMap)[i][j+2].height==height&&
                        (*info.theMap)[i+1][j+2].height==height&&
                        (*info.theMap)[i+2][j+1].height==height&&
                        (*info.theMap)[i+2][j+2].height==height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                        buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        /*
        if(start_x>63||start_y<63)
        {
            start_x=63,start_y=63;
        }
        if(find_block3_4(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info)&&
          (*info.theMap)[x-1][y].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x][y-1].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x+3][y].type!=MAPPATTERN_OCEAN&&(*info.theMap)[x][y+3].type!=MAPPATTERN_OCEAN)
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
            buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }*/
        break;
    }
}
//村民建造兵营
static bool s=true;
void UsrAI::farmer_to_armycamp(tagInfo info)
{
    int x=0,y=0;
    switch (branch) {
    case 1:
        if(find_block3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x,y+1,info)&&idleblock(x+2,y,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y,info)&&
           idleblock(x+1,y+1,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+1,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARMYCAMP,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造兵营");
            buildingArmycampFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    case 2:
        for(int i=land_X1+30;i>land_X1-30;i--)
        {
            for(int j=land_Y1+30;j>land_Y1-30;j--)
            {
                if((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS &&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARMYCAMP,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造兵营");
                        buildingArmycampFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        break;
    case 3:
        if(find_block3_3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x,y+1,info)&&idleblock(x+2,y,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y,info)&&
           idleblock(x+1,y+1,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+1,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARMYCAMP,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造兵营");
            buildingArmycampFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    default:
        for(int j=land_Y1-20;j<128;j++)
        {
            for(int i=land_X1+20;i>0;i--)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+2].type==MAPPATTERN_GRASS&&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height==height&&
                        (*info.theMap)[i][j+1].height==height&&
                        (*info.theMap)[i+1][j+1].height==height&&
                        (*info.theMap)[i+2][j].height==height&&
                        (*info.theMap)[i][j+2].height==height&&
                        (*info.theMap)[i+1][j+2].height==height&&
                        (*info.theMap)[i+2][j+1].height==height&&
                        (*info.theMap)[i+2][j+2].height==height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                        buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        /*
        if(find_block3_4(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x,y+1,info)&&idleblock(x+2,y,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y,info)&&
           idleblock(x+1,y+1,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+1,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARMYCAMP,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造兵营");
            buildingArmycampFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }*/
        break;
    }
}
//村民建造靶场
void UsrAI::farmer_to_range(tagInfo info)
{
    int x=0,y=0;
    switch (branch) {
    case 1:
        if(find_block3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_RANGE,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造靶场");
            buildingRangeFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    case 2:
        for(int i=land_X1+30;i>0;i--)
        {
            for(int j=land_Y1+30;j>0;j--)
            {
                if((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS &&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_RANGE,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造靶场");
                        buildingRangeFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        break;
    case 3:
        if(find_block3_3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_RANGE,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造靶场");
            buildingRangeFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    default:
        for(int j=land_Y1-20;j<128;j++)
        {
            for(int i=land_X1+20;i>0;i--)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+2].type==MAPPATTERN_GRASS&&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height==height&&
                        (*info.theMap)[i][j+1].height==height&&
                        (*info.theMap)[i+1][j+1].height==height&&
                        (*info.theMap)[i+2][j].height==height&&
                        (*info.theMap)[i][j+2].height==height&&
                        (*info.theMap)[i+1][j+2].height==height&&
                        (*info.theMap)[i+2][j+1].height==height&&
                        (*info.theMap)[i+2][j+2].height==height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                        buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        /*
        if(find_block3_4(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_RANGE,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造靶场");
            buildingRangeFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }*/
        break;
    }
}
//村民建造马厩
void UsrAI::farmer_to_stable(tagInfo info)
{   
    int x=0,y=0;
    switch (branch) {
    case 1:
        if(find_block3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STABLE,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造马厩");
            buildingStableFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    case 2:
        for(int i=land_X1+30;i>0;i--)
        {
            for(int j=land_Y1+30;j>0;j--)
            {
                if((*info.theMap)[i][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i][j+2].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+1][j+2].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j+1].type == MAPPATTERN_GRASS &&
                   (*info.theMap)[i+2][j+2].type == MAPPATTERN_GRASS &&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height == height &&
                        (*info.theMap)[i][j+1].height == height &&
                        (*info.theMap)[i+1][j+1].height == height &&
                        (*info.theMap)[i+2][j].height == height &&
                        (*info.theMap)[i][j+2].height == height &&
                        (*info.theMap)[i+1][j+2].height == height &&
                        (*info.theMap)[i+2][j+1].height == height &&
                        (*info.theMap)[i+2][j+2].height == height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STABLE,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造马厩");
                        buildingStableFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        break;
    case 3:
        if(find_block3_3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STABLE,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造马厩");
            buildingStableFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    default:
        for(int j=land_Y1-20;j<128;j++)
        {
            for(int i=land_X1+20;i>0;i--)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j+2].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+1].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+2][j+2].type==MAPPATTERN_GRASS&&
                   idleblock(i,j,info)&&idleblock(i+1,j,info)&&idleblock(i,j+1,info)&&idleblock(i+1,j+1,info)&&
                   idleblock(i+2,j,info)&&idleblock(i+2,j+1,info)&&idleblock(i,j+2,info)&&idleblock(i+1,j+2,info)&&idleblock(i+2,j+2,info))
                {
                    int height = (*info.theMap)[i][j].height;
                    if ((*info.theMap)[i+1][j].height==height&&
                        (*info.theMap)[i][j+1].height==height&&
                        (*info.theMap)[i+1][j+1].height==height&&
                        (*info.theMap)[i+2][j].height==height&&
                        (*info.theMap)[i][j+2].height==height&&
                        (*info.theMap)[i+1][j+2].height==height&&
                        (*info.theMap)[i+2][j+1].height==height&&
                        (*info.theMap)[i+2][j+2].height==height)
                    {
                        // 找到符合条件的3*3空地，返回左下角坐标
                        DebugText("找到空地：("+QString::number(i)+","+QString::number(j)+")");
                        HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,i,j);
                        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                        buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                        e_idleFarmer.pop_back();
                        return;
                    }
                }
            }
        }
        /*
        if(find_block3_4(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STABLE,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造马厩");
            buildingStableFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }*/
        break;
    }
}
//村民在岸附近探索
static int sx=0,sy=0;
void UsrAI::farmer_explore(tagInfo info)
{
    int i,j;
    double d=0xffffffff;
    double t=0;
    int x,y;
    switch (branch) {
    case 1:
        for(i=50;i<land_X1+17;i++)
        {
            for(j=50;j<land_Y1+17;j++)
            if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i+1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type!=MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&
               i!=0&&j!=0&&
               idleblock(i,j,info)&&i!=e_idleFarmer[e_idleFarmer.size()-1].BlockDR&&j!=e_idleFarmer[e_idleFarmer.size()-1].BlockUR)
            {
                t=sqrt((i-e_idleFarmer[e_idleFarmer.size()-1].BlockDR)*(i-e_idleFarmer[e_idleFarmer.size()-1].BlockDR)+(j-e_idleFarmer[e_idleFarmer.size()-1].BlockUR)*(j-e_idleFarmer[e_idleFarmer.size()-1].BlockUR));
                if(t<d)
                {
                    d=t;
                    x=i;
                    y=j;
                }
            }
        }
        if(d==0xffffffff)return;
        HumanMove(e_idleFarmer[e_idleFarmer.size()-1].SN,x*BLOCKSIDELENGTH,y*BLOCKSIDELENGTH);
        exploringFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
        e_idleFarmer.pop_back();
        break;
    case 2:
        for(i=land_X1+20;i>land_X1-20;i--)
        {
            for(j=land_Y1+30;j>land_Y1-30;j--)
            if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i+1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type!=MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&
               i!=0&&j!=0&&
               idleblock(i,j,info)&&i!=e_idleFarmer[e_idleFarmer.size()-1].BlockDR&&j!=e_idleFarmer[e_idleFarmer.size()-1].BlockUR)
            {
                t=sqrt((i-e_idleFarmer[e_idleFarmer.size()-1].BlockDR)*(i-e_idleFarmer[e_idleFarmer.size()-1].BlockDR)+(j-e_idleFarmer[e_idleFarmer.size()-1].BlockUR)*(j-e_idleFarmer[e_idleFarmer.size()-1].BlockUR));
                if(t<d)
                {
                    d=t;
                    x=i;
                    y=j;
                }
            }
        }
        if(d==0xffffffff)return;
        HumanMove(e_idleFarmer[e_idleFarmer.size()-1].SN,x*BLOCKSIDELENGTH,y*BLOCKSIDELENGTH);
        exploringFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
        e_idleFarmer.pop_back();
        break;
    case 3:
        for(i=63;i>land_X1-10;i--)
        {
            for(j=63;j>land_Y1-20;j--)
            if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i+1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type!=MAPPATTERN_OCEAN&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&
               i!=0&&j!=0&&
               idleblock(i,j,info)&&i!=e_idleFarmer[e_idleFarmer.size()-1].BlockDR&&j!=e_idleFarmer[e_idleFarmer.size()-1].BlockUR)
            {
                t=sqrt((i-e_idleFarmer[e_idleFarmer.size()-1].BlockDR)*(i-e_idleFarmer[e_idleFarmer.size()-1].BlockDR)+(j-e_idleFarmer[e_idleFarmer.size()-1].BlockUR)*(j-e_idleFarmer[e_idleFarmer.size()-1].BlockUR));
                if(t<d)
                {
                    d=t;
                    x=i;
                    y=j;
                }
            }
        }
        if(d==0xffffffff)return;
        HumanMove(e_idleFarmer[e_idleFarmer.size()-1].SN,x*BLOCKSIDELENGTH,y*BLOCKSIDELENGTH);
        exploringFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
        e_idleFarmer.pop_back();
        break;
    default:
        if(sx==0&&sy==0)
        {
            sx=127;
            sy=0;
        }
        if(i==(land_X1-20)&&j==(land_Y1+20))
        {
            sx=127;
            sy=0;
        }
        for(i=sx;i>land_X1-20;i--)
        {
            for(j=sy;j<land_Y1+20;j++)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                   (*info.theMap)[i+1][j].type!=MAPPATTERN_OCEAN&&
                   (*info.theMap)[i-1][j].type!=MAPPATTERN_OCEAN&&
                   (*info.theMap)[i][j+1].type!=MAPPATTERN_OCEAN&&
                   (*info.theMap)[i][j-1].type!=MAPPATTERN_OCEAN&&
                  ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&
                   idleblock(i,j,info))
                {
                    HumanMove(e_idleFarmer[e_idleFarmer.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    exploringFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                    e_idleFarmer.pop_back();
                    sx=i-1;
                    sy=j+1;
                    return;
                }
            }
        }
        break;
    }
}
//判断是否找到黄金
bool UsrAI::have_gold(tagInfo info)
{
    for(tagResource Resource:info.resources)
    {
        if(Resource.Type==RESOURCE_GOLD)
            return true;
    }
    return false;
}
//不超过k个村民采金
void UsrAI::farmer_to_gold(int k,tagInfo info)
{
    while(e_idleFarmer.size()&&goldFarmer.size()<k)
    {
        HumanAction(e_idleFarmer[e_idleFarmer.size()-1].SN,findResource(e_idleFarmer[e_idleFarmer.size()-1],RESOURCE_GOLD,info));
        DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"采金");
        goldFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
        e_idleFarmer.pop_back();
    }
}
//骑兵寻找敌军
//攻击
void UsrAI::scout_attack(int obSN,tagInfo info)
{
    HumanAction(idleScout[idleScout.size()-1].SN,obSN);
    attackingScout.push_back(idleScout[idleScout.size()-1]);
    idleScout.pop_back();
}
//
static int tx=0,ty=0;
void UsrAI::scout_explore(tagInfo info)
{
    int i,j;
    if(tx==0&&ty==0)
    {
        tx=63;
        ty=63;
    }
    switch (branch) {
    case 1:
        if(i==127&&j==127)
        {
            tx=63;
            ty=63;
        }
        for(i=tx;i<127;i++)
        {
            for(j=ty;j<127;j++)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                  ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&idleblock(i,j,info))
                {
                    HumanMove(idleScout[idleScout.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    movingScout.push_back(idleScout[idleScout.size()-1]);
                    idleScout.pop_back();
                    tx=i+2;
                    ty=j+3;
                    return;
                }
            }
        }
        break;
    case 2:
        if(i==127&&j==0)
        {
            tx=63;
            ty=63;
        }
        for(i=tx;i<127;i++)
        {
            for(j=ty;j>0;j--)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                  ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&idleblock(i,j,info))
                {
                    HumanMove(idleScout[idleScout.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    movingScout.push_back(idleScout[idleScout.size()-1]);
                    idleScout.pop_back();
                    tx=i;
                    ty=j-1;
                    return;
                }
            }
        }
        break;
    case 3:
        if(i==0&&j==0)
        {
            tx=63;
            ty=50;
        }
        for(j=ty;j<128;j++)
        {
            for(i=tx;i>0;i--)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                  ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&idleblock(i,j,info))
                {
                    HumanMove(idleScout[idleScout.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    movingScout.push_back(idleScout[idleScout.size()-1]);
                    idleScout.pop_back();
                    tx=i-1;
                    ty=j;
                    return;
                }
            }
        }
        break;
    default:
        if(i==0&&j==127)
        {
            tx=63;
            ty=63;
        }
        for(i=tx;i>0;i--)
        {
            for(j=ty;j<127;j++)
            {
                if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                  ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
                   (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&idleblock(i,j,info))
                {
                    HumanMove(idleScout[idleScout.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                    movingScout.push_back(idleScout[idleScout.size()-1]);
                    idleScout.pop_back();
                    tx=i;
                    ty=j+1;
                    return;
                }
            }
        }
        break;
    }
}
void UsrAI::scout_explore2(tagInfo info)
{
    double d=0xffffffff;
    double t=0;
    int x,y;
    for(int i=0;i<128;i++)
    {
        for(int j=0;j<128;j++)
        {

            if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
               (*info.theMap)[i+1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i-1][j].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j+1].type!=MAPPATTERN_OCEAN&&
               (*info.theMap)[i][j-1].type!=MAPPATTERN_OCEAN&&
                no_forest(i,j,info)&&
              ((*info.theMap)[i+1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i-1][j].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j+1].type==MAPPATTERN_UNKNOWN||
               (*info.theMap)[i][j-1].type==MAPPATTERN_UNKNOWN)&&
               i!=0&&j!=0&&i!=127&&j!=127&&
               idleblock(i,j,info)&&i!=idleScout[idleScout.size()-1].BlockDR&&j!=idleScout[idleScout.size()-1].BlockUR)
            {
                t=sqrt((i-idleScout[idleScout.size()-1].BlockDR)*(i-idleScout[idleScout.size()-1].BlockDR)+(j-idleScout[idleScout.size()-1].BlockUR)*(j-idleScout[idleScout.size()-1].BlockUR));
                if(t<d)
                {
                    d=t;
                    x=i;
                    y=j;
                }
            }
        }
    }
    if(d==0xffffffff)return;
    HumanMove(idleScout[idleScout.size()-1].SN,x*BLOCKSIDELENGTH,y*BLOCKSIDELENGTH);
    movingScout.push_back(idleScout[idleScout.size()-1]);
    idleScout.pop_back();
}
//战略部署
//斧头兵
//集合至敌军前线坐标，发现敌人立即攻打
void UsrAI::swordsman_part(int obSN,tagInfo info)
{
    HumanAction(idleSwordsman[idleSwordsman.size()-1].SN,obSN);
    attackingSwordsman.push_back(idleSwordsman[idleSwordsman.size()-1]);
    idleSwordsman.pop_back();
}
//投石兵
//集合至敌军前线坐标，优先攻打箭塔、弓箭手
void UsrAI::slinger_part(int obSN,tagInfo info)
{
    HumanAction(idleSlinger[idleSlinger.size()-1].SN,obSN);
    attackingSlinger.push_back(idleSlinger[idleSlinger.size()-1]);
    idleSlinger.pop_back();
}
//弓箭手
//找到附近高地并集结，攻打较低地势敌军
void UsrAI::bowman_attack(int obSN,tagInfo info)
{
    HumanAction(idleBowman[idleBowman.size()-1].SN,obSN);
    attackingBowman.push_back(idleBowman[idleBowman.size()-1]);
    idleBowman.pop_back();
}
//棍棒兵
void UsrAI::clubman_part(int obSN,tagInfo info)
{
    HumanAction(idleclubman[idleclubman.size()-1].SN,obSN);
    attackingclubman.push_back(idleclubman[idleclubman.size()-1]);
    idleclubman.pop_back();
}
//战船
void UsrAI::ship_attack(int obSN,tagInfo info)
{
    HumanAction(idleShip[idleShip.size()-1].SN,obSN);
    attackingShip.push_back(idleShip[idleShip.size()-1]);
    idleShip.pop_back();
}
void UsrAI::decide_enemy_block(tagInfo info)
{
    if(info.enemy_armies.size()==0&&info.enemy_buildings.size()==0)return;
    for(tagArmy enemy:info.enemy_armies)
    {
        if(enemy.Sort!=AT_SHIP)
        {
            if(idleScout.size())
            {
                scout_attack(enemy.SN,info);
                return;
            }
            if(idleSwordsman.size())
            {
                swordsman_part(enemy.SN,info);
                return;
            }
            if(idleSlinger.size())
            {
                slinger_part(enemy.SN,info);
                return;
            }
            if(idleBowman.size())
            {
                bowman_attack(enemy.SN,info);
                return;
            }
            if(idleclubman.size())
            {
                clubman_part(enemy.SN,info);
                return;
            }
            if(idleShip.size())
            {
                ship_attack(enemy.SN,info);
                return;
            }
        }
    }
    for(tagBuilding building:info.enemy_buildings)
    {
        if(idleScout.size())
        {
            scout_attack(building.SN,info);
            return;
        }
        if(idleSwordsman.size())
        {
            swordsman_part(building.SN,info);
            return;
        }
        if(idleSlinger.size())
        {
            slinger_part(building.SN,info);
            return;
        }
        if(idleBowman.size())
        {
            bowman_attack(building.SN,info);
            return;
        }
        if(idleclubman.size())
        {
            clubman_part(building.SN,info);
            return;
        }
        if(idleShip.size())
        {
            ship_attack(building.SN,info);
            return;
        }
    }
}
//建造箭塔，位于高地
void UsrAI::farmer_to_arrowtower(tagInfo info)
{
    int x=0,y=0;
    switch (branch) {
    case 1:
        if(find_block3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARROWTOWER,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造箭塔");
            buildingArrowtowerFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    case 2:
        if(find_block3_2(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info)&&
           (*info.theMap)[x][y].height!=0)
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARROWTOWER,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造箭塔");
            buildingArrowtowerFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    case 3:
        if(find_block3_3(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info)&&
           (*info.theMap)[x][y].height!=0)
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARROWTOWER,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造箭塔");
            buildingArrowtowerFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    default:
        if(find_block3_4(x,y,info)&&
           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&idleblock(x+1,y,info)&&
           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info)&&
           (*info.theMap)[x][y].height!=0)
        {
            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_ARROWTOWER,x,y);
            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造箭塔");
            buildingArrowtowerFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
            e_idleFarmer.pop_back();
        }
        break;
    }
}
static int g_x=0,g_y=0;
bool UsrAI::many_gold(tagInfo info,char map[][128])
{
    if(g_x!=0&&g_y!=0)return true;
    for(int i=0;i<128;i++)
    {
        for(int j=0;j<128;j++)
        {
            if(map[i][j]=='w'&&map[i+2][j]=='w'&&map[i][j+2]=='w'&&map[i-2][j]=='w'&&map[i][j-2]=='w')
            {
                g_x=i,g_y=j;
                return true;
            }
        }
    }
    return false;
}
void UsrAI::processData()
{
    tagInfo info = getInfo();
    static int stage=1;
    static int wx=0,wy=0;
    //创建实时map
    char map[128][128];
    createMAP(map,info);
    //show_MAP(map);
    arrangeFarmer(info);
    if((stage==2&&Boat_farmer.size()>=5)||stage==3)
    {
        push_Boat_farmer(info);
        arrangeE_farmer(info);
        sort_E_idlefarmer(info);
    }
    arrangeHome(info);
    arrangeCenter(info);
    arrangeDock(info);
    arrangeSailingBoat(info);
    arrangeWoodBoat(info);
    arrangeMarket(info);
    arrangeFarm(info);
    arrangeGranary(info);
    arrangeShip(info);
    arrangeStock(info);
    arrangeArmycamp(info);
    arrangeRange(info);
    arrangeStable(info);
    arrangeArrowtower(info);
    arrangeArmy_on_land(info);
    switch(stage)
    {
        case 1:
               //派1个村民捕猎大象
               if(idleFarmer.size()&&huntingELFarmer.size()<1)
                   farmer_hunt_EL(1,info);
               if(idleFarmer.size()&&huntingELFarmer.size()<1&&hunter.Blood==0)
                   farmer_hunt_EL2(2,info);
               //派2个村民砍树
               if(cuttingFarmer.size()==0&&info.farmers.size()<10)farmer_to_tree(2,info);
               //obj：建造1个船坞
               static tagFarmer tp;
               if(idleDock.size()+createSailingDock.size()+createWoodBoatDock.size()+createShipDock.size()<1&&buildingDockFarmer.size()<1&&info.Wood>=BUILD_DOCK_WOOD)
               {
                   farmer_to_dock(info);
                   tp=buildingDockFarmer[buildingDockFarmer.size()-1];
               }
               if(bornDock.size()&&idleFarmer.size()&&buildingDockFarmer.size()<2)
               {
                   HumanAction(idleFarmer[idleFarmer.size()-1].SN,bornDock[bornDock.size()-1].SN);
                   buildingDockFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
                   idleFarmer.pop_back();
               }
               if(idleDock.size()+createSailingDock.size()+createWoodBoatDock.size()+createShipDock.size()>=1&&buildingDockFarmer.size())
               {
                   HumanAction(tp.SN,findResource(tp, RESOURCE_TREE,info));
                   DebugText("安排农民" + QString::number(tp.SN) + "砍树");
                   cuttingFarmer.push_back(tp);            // 加入砍树农民数组
                   buildingDockFarmer.pop_back();
               }
               //obj：造9个房子
               if(idleHome.size()+bornHome.size()<9&&idleFarmer.size()&&info.Wood>=BUILD_HOUSE_WOOD)
               {
                   DebugText("目前有："+QString::number(idleHome.size()+bornHome.size())+"个房屋");
                   farmer_to_home(info);
               }
               //obj：建造谷仓
               if(idleHome.size()>=3&&idleGranary.size()+arrowtowerGranary.size()+bornGranary.size()==0&&idleFarmer.size()&&info.Wood>=BUILD_GRANARY_WOOD)
                   farmer_to_granary(info);
               //obj：派1个村民打猎不超过5只羚羊
               if(huntingGZFarmer.size()==0)
                   farmer_hunt_GZ(info,5);
               //obj：安排8个村民捕鱼
               if(idleHome.size()>=2&&idleFarmer.size()&&fishingFarmer.size()<8&&findFish(idleFarmer[idleFarmer.size()-1],info)!=-1)
                   farmer_to_fish(info,8);
               //obj：生产11个村民，单帧生产1个
               if(info.farmers.size()-idlesailingBoat.size()-fishingsailingBoat.size()<15&&idleCenter.size()&&info.Meat>=BUILDING_CENTER_CREATEFARMER_FOOD)
               {
                   BuildingAction(idleCenter[idleCenter.size()-1].SN,BUILDING_CENTER_CREATEFARMER);
                   createHumanCenter.push_back(idleCenter[idleCenter.size()-1]);
                   idleCenter.pop_back();
               }
               //obj：当已生产15个村民岸边渔场已尽时，派4个捕猎瞪羚，10个伐木
               if(idleFarmer.size()+cuttingFarmer.size()+huntingGZFarmer.size()+fishingFarmer.size()+buildingDockFarmer.size()+buildingGranaryFarmer.size()+buildingHouseFarmer.size()>=15&&
                  findFish(idleFarmer[idleFarmer.size()-1],info)==-1&&idleFarmer.size()&&cuttingFarmer.size()<10)
               {
                   farmer_to_tree(10,info);
               }
               if(idleFarmer.size()+cuttingFarmer.size()+huntingGZFarmer.size()+fishingFarmer.size()+buildingDockFarmer.size()+buildingGranaryFarmer.size()+buildingHouseFarmer.size()>=14&&
                  findFish(idleFarmer[idleFarmer.size()-1],info)==-1&&idleFarmer.size()&&huntingGZFarmer.size()<3)
               {
                   farmer_hunt_GZ(info,6);
               }
               //obj：建造5艘渔船
               static int num=0;
               if(num<5&&idleDock.size()>0&&info.Wood>=BUILDING_DOCK_CREATE_SAILING_WOOD&&info.farmers.size()<(4*idleHome.size()+4))
               {
                   DebugText("造渔船");
                   BuildingAction(idleDock[idleDock.size()-1].SN,BUILDING_DOCK_CREATE_SAILING);
                   createSailingDock.push_back(idleDock[idleDock.size()-1]);
                   idleDock.pop_back();
                   num++;
               }
               //obj：造好5条渔船集体捕鱼
               if(idlesailingBoat.size()&&findResource(idlesailingBoat[idlesailingBoat.size()-1],RESOURCE_FISH,info)!=0)
                   sailing_to_fish(1,info);
               if(idlesailingBoat.size()&&findResource(idlesailingBoat[idlesailingBoat.size()-1],RESOURCE_FISH,info)==0)
                   sailing_explore(info);
               //升级时代（执行一次）
               static int optime=0;
               if(info.Meat>=500&&optime==0)
               {
                   BuildingAction(idleCenter[idleCenter.size()-1].SN,BUILDING_CENTER_UPGRADE);
                   optime++;
               }
               if(info.civilizationStage==CIVILIZATION_TOOLAGE&&idleGranary.size()&&idleHome.size()>=9)stage++;
               break;
        case 2:
               //obj：造好5条渔船集体捕鱼
             if(idlesailingBoat.size())
             {
                 if(findResource(idlesailingBoat[idlesailingBoat.size()-1],RESOURCE_FISH,info)==0&&land_X1!=0&&land_Y1!=0)
                    sailing_explore(info);
                 else sailing_to_fish(1,info);
             }
               //obj：派4个村民建设市场
               static bool Market_flag=true;
               if(idleFarmer.size()&&buildingMarketFarmer.size()<4&&
                  idleDock.size()+createSailingDock.size()+createWoodBoatDock.size()+createShipDock.size()+bornDock.size()>=2&&
                  idleMarket.size()+upgradeFarmMarket.size()+upgradeStoneMarket.size()+upgradeWoodMarket.size()==0&&info.Wood>=BUILD_MARKET_WOOD)
               {
                   if(Market_flag)
                   {
                       farmer_to_market(info);
                       Market_flag=false;
                   }
                   else
                   {
                       HumanAction(idleFarmer[idleFarmer.size()-1].SN,bornMarket[bornMarket.size()-1].SN);
                       DebugText("安排村民"+QString::number(idleFarmer[idleFarmer.size()-1].SN)+"继续修建市场");
                       buildingMarketFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
                       idleFarmer.pop_back();
                   }
               }
               //obj：建造1个船坞
               static tagFarmer tp1;
               if(idleDock.size()+createSailingDock.size()+createWoodBoatDock.size()+createShipDock.size()+bornDock.size()<2&&idleFarmer.size()&&info.Wood>=BUILD_DOCK_WOOD)
               {
                   DebugText("造船坞");
                   farmer_to_dock(info);
                   tp1=buildingDockFarmer[buildingDockFarmer.size()-1];
               }
               if(bornDock.size()&&idleFarmer.size()&&buildingDockFarmer.size()<2)
               {
                   HumanAction(idleFarmer[idleFarmer.size()-1].SN,bornDock[bornDock.size()-1].SN);
                   buildingDockFarmer.push_back(idleFarmer[idleFarmer.size()-1]);
                   idleFarmer.pop_back();
               }
               if(idleDock.size()+createSailingDock.size()+createWoodBoatDock.size()+createShipDock.size()>=2&&buildingDockFarmer.size())
               {
                   HumanAction(tp1.SN,findResource(tp1, RESOURCE_TREE,info));
                   DebugText("安排农民" + QString::number(tp1.SN) + "砍树");
                   cuttingFarmer.push_back(tp1);            // 加入砍树农民数组
                   buildingDockFarmer.pop_back();
               }
               //obj：开始，派12个村民砍树
               if(idleFarmer.size()&&cuttingFarmer.size()<10&&land_X1==0&&land_Y1==0)
                   farmer_to_tree(12,info);
               //obj：派1个村民挖矿
               if(idleFarmer.size()&&miningFarmer.size()<1)
                   farmer_to_stone(1,info);
               //obj：持续造4艘战船
               if(idleDock.size()>=2&&idleShip.size()+exploringShip.size()+attackingShip.size()+createShipDock.size()<4&&
                  info.Wood>=2*BUILDING_DOCK_CREATE_SHIP_WOOD&&land_X1==0&&land_Y1==0&&idleWoodBoat.size()+movingWoodBoat.size()>0)
               {
                   DebugText("idleShip:"+QString::number(idleShip.size()));
                   DebugText("exploringShip:"+QString::number(exploringShip.size()));
                   DebugText("attackingShip:"+QString::number(attackingShip.size()));
                   Dock_to_ship(2,info);
               }
               if(land_X1!=0&&land_Y1!=0&&idleShip.size())
               {
                   ship_find_enemy2(info);
               }
               //obj：建造一艘运输船
               if(idleHome.size()>3&&idleDock.size()&&idleDock.size()+createSailingDock.size()+createShipDock.size()+createWoodBoatDock.size()>=2&&
                       createWoodBoatDock.size()+idleWoodBoat.size()+movingWoodBoat.size()==0&&info.Wood>=BUILDING_DOCK_CREATE_WOOD_BOAT_WOOD)
               {
                   BuildingAction(idleDock[idleDock.size()-1].SN,BUILDING_DOCK_CREATE_WOOD_BOAT);
                   DebugText("安排船坞"+QString::number(idleDock[idleDock.size()-1].SN)+"修建运输船");
                   createWoodBoatDock.push_back(idleDock[idleDock.size()-1]);
                   idleDock.pop_back();
               }   
               //obj：在市镇中心附近建设农田
               if(idleMarket.size()+upgradeFarmMarket.size()+upgradeStoneMarket.size()+upgradeWoodMarket.size()>0&&
                  idleFarmer.size()&&idleFarm.size()+bornFarm.size()<1&&info.Wood>=BUILD_FARM_WOOD&&land_X1==0&&land_Y1==0)
               {
                   farmer_to_farm(info);
               }
               //obj：若找到陆地，只派5个村民砍树
               if(land_X1!=0&&land_Y1!=0&&idleFarmer.size()&&cuttingFarmer.size()<3)
                   farmer_to_tree(5,info);
               //obj：开始，依次派遣战船探索
               /*
               if(idleShip.size())
                   is_enemy_ship(info);*/
               static bool shipflag=false;
               if(idleShip.size()>3&&land_X1==0&&land_Y1==0&&!shipflag)
               {
                   if(x_ocean==0&&y_ocean==0)find_begin_sea(info);
                   ship_find_enemy1(info);
                   decide_land1(info);
                   shipflag=true;
               }
               //后续即时补给
               if(shipflag&&land_X1==0&&land_Y1==0&&idleShip.size())
               {
                   ship_find_enemy1(info);
                   decide_land1(info);
               }
               //obj：运输船移动到岸边
               static int xx=idleDock[idleDock.size()-1].BlockDR,yy=idleDock[idleDock.size()-1].BlockUR;
               static bool woodboatmove=true;
               if(woodboatmove&&idleWoodBoat.size())
               {
                   for(int i=xx-4;i<=xx+4;i++)
                   {
                       for(int j=yy-4;j<=yy+4;j++)
                       {
                           if((*info.theMap)[i][j].type==MAPPATTERN_GRASS&&
                               idleblock(i,j,info)&&
                             ((*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN||
                              (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN||
                              (*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN||
                              (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN))
                           {
                               HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                               wx=i,wy=j;
                               woodboatmove=false;
                           }
                       }
                   }
               }
               //obj：生产的战船停靠岸边，防止拥堵
               static bool shipmove=true;
               if(idleShip.size()==2&&land_X1==0&&land_Y1==0&&shipmove)
               {
                   for(int i=xx-3;i<=xx+3,idleShip.size()>0;i++)
                   {
                       for(int j=yy-3;j<=yy+3,idleShip.size()>0;j++)
                       {
                           if((*info.theMap)[i][j].type==MAPPATTERN_OCEAN&&
                               idleblock(i,j,info)&&
                              (*info.theMap)[i+1][j].type==MAPPATTERN_OCEAN&&
                              (*info.theMap)[i][j+1].type==MAPPATTERN_OCEAN&&
                              (*info.theMap)[i-1][j].type==MAPPATTERN_OCEAN&&
                              (*info.theMap)[i][j-1].type==MAPPATTERN_OCEAN)
                           {
                               HumanMove(idleShip[idleShip.size()-1].SN,i*BLOCKSIDELENGTH,j*BLOCKSIDELENGTH);
                               exploringShip.push_back(idleShip[idleShip.size()-1]);
                               idleShip.pop_back();
                           }
                       }
                   }
                   shipmove=false;
               }
               //obj：若找到登陆坐标，派5个村民登船
               if(land_X1!=0&&land_Y1!=0&&idleWoodBoat.size()+movingWoodBoat.size()>0&&Boat_farmer.size()<5&&idleFarmer.size()&&farmer_on_boat(info))
               {
                   DebugText("!");
                   farmer_to_WoodBoat(info);
               }
               //obj：派运输船前往登陆坐标
               static bool boat_land=true;
               if(Boat_farmer.size()>=5&&boat_land&&idleWoodBoat.size()+movingWoodBoat.size()>=1&&land_X1!=0&&land_Y1!=0&&farmer_on_boat(info))
               {
                   if(movingWoodBoat.size())
                   {
                       switch (branch) {
                       case 1:
                           HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+40,land_Y1*BLOCKSIDELENGTH+40);
                           break;
                       case 2:
                           HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+10,land_Y1*BLOCKSIDELENGTH-10);
                           break;
                       case 3:
                           HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH-10);
                           break;
                       default:
                           HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH+10);
                           break;
                       }
                       boat_land=false;
                   }
                   else
                   {
                       switch (branch) {
                       case 1:
                           HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+40,land_Y1*BLOCKSIDELENGTH+40);
                           break;
                       case 2:
                           HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+10,land_Y1*BLOCKSIDELENGTH-10);
                           break;
                       case 3:
                           HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH-10);
                           break;
                       default:
                           HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH+10);
                           break;
                       }
                       boat_land=false;
                   }
               }
               //obj：技术升级模块
               //谷仓研发箭塔
               /*
               static bool research=true;
               if(idleGranary.size()&&research&&info.Meat>=BUILDING_GRANARY_ARROWTOWER_FOOD&&Wood_Level>1)
               {
                   BuildingAction(idleGranary[idleGranary.size()-1].SN,BUILDING_GRANARY_ARROWTOWER);
                   arrowtowerGranary.push_back(idleGranary[idleGranary.size()-1]);
                   idleGranary.pop_back();
                   research=false;
               }*/
               //升级伐木
               if(idleMarket.size()&&info.Wood>=BUILDING_MARKET_WOOD_UPGRADE_WOOD&&info.Meat>=BUILDING_MARKET_WOOD_UPGRADE_FOOD)
               {
                   BuildingAction(idleMarket[idleMarket.size()-1].SN,BUILDING_MARKET_WOOD_UPGRADE);
                   upgradeWoodMarket.push_back(idleMarket[idleMarket.size()-1]);
                   idleMarket.pop_back();
                   Wood_Level++;
               }
               //升级采矿
               if(idleMarket.size()&&info.Meat>=BUILDING_MARKET_STONE_UPGRADE_FOOD&&info.Stone>=BUILDING_MARKET_STONE_UPGRADE_STONE&&Wood_Level>1)
               {
                   BuildingAction(idleMarket[idleMarket.size()-1].SN,BUILDING_MARKET_STONE_UPGRADE);
                   upgradeStoneMarket.push_back(idleMarket[idleMarket.size()-1]);
                   idleMarket.pop_back();
                   Stone_Level++;
               }
               /*
               //升级农田
               if(idleMarket.size()&&info.Meat>=BUILDING_MARKET_FARM_UPGRADE_FOOD&&info.Wood>=BUILDING_MARKET_FARM_UPGRADE_WOOD&&idleFarm.size()&&shipflag)
               {
                   BuildingAction(idleMarket[idleMarket.size()-1].SN,BUILDING_MARKET_FARM_UPGRADE);
                   upgradeFarmMarket.push_back(idleMarket[idleMarket.size()-1]);
                   idleMarket.pop_back();
                   Farm_Level++;
               }*/
               //升级工具利用
               if(idleStock.size()&&Wood_Level>1&&info.Meat>=BUILDING_STOCK_UPGRADE_USETOOL_FOOD)
               {
                   BuildingAction(idleStock[idleStock.size()-1].SN,BUILDING_STOCK_UPGRADE_USETOOL);
                   upgradeToolStock.push_back(idleStock[idleStock.size()-1]);
                   idleStock.pop_back();
                   Tool_Level++;
               }
               //升级骑兵护甲
               if(idleStock.size()&&Wood_Level>1&&info.Meat>=BUILDING_STOCK_UPGRADE_DEFENSE_RIDER_FOOD)
               {
                   BuildingAction(idleStock[idleStock.size()-1].SN,BUILDING_STOCK_UPGRADE_DEFENSE_RIDER);
                   upgradeDefenseRiderStock.push_back(idleStock[idleStock.size()-1]);
                   idleStock.pop_back();
                   Defense_Rider_Level++;
               }
               //升级步兵护甲
               if(idleStock.size()&&Wood_Level>1&&info.Meat>=BUILDING_STOCK_UPGRADE_DEFENSE_INFANTRY_FOOD)
               {
                   BuildingAction(idleStock[idleStock.size()-1].SN,BUILDING_STOCK_UPGRADE_DEFENSE_INFANTRY);
                   upgradeDefenseInfantryStock.push_back(idleStock[idleStock.size()-1]);
                   idleStock.pop_back();
                   Defense_Infantry_Level++;
               }
               //检查村民是否登陆
               if(farmer_to_land(5,info))farmer_explore(info);
               if(farmer_to_land(5,info)&&info.Wood>=BUILD_STOCK_WOOD&&Tool_Level>1)stage++;
               break;
        default:
            //升级骑兵护甲
            if(idleStock.size()&&Defense_Rider_Level<2&&info.Meat>=BUILDING_STOCK_UPGRADE_DEFENSE_RIDER_FOOD)
            {
                BuildingAction(idleStock[idleStock.size()-1].SN,BUILDING_STOCK_UPGRADE_DEFENSE_RIDER);
                upgradeDefenseRiderStock.push_back(idleStock[idleStock.size()-1]);
                idleStock.pop_back();
                Defense_Rider_Level++;
            }
            //升级步兵护甲
            if(idleStock.size()&&Defense_Infantry_Level<2&&info.Meat>=BUILDING_STOCK_UPGRADE_DEFENSE_INFANTRY_FOOD)
            {
                BuildingAction(idleStock[idleStock.size()-1].SN,BUILDING_STOCK_UPGRADE_DEFENSE_INFANTRY);
                upgradeDefenseInfantryStock.push_back(idleStock[idleStock.size()-1]);
                idleStock.pop_back();
                Defense_Infantry_Level++;
            }
            //obj：造好5条渔船集体捕鱼
            if(idlesailingBoat.size())
            {
                if(findResource(idlesailingBoat[idlesailingBoat.size()-1],RESOURCE_FISH,info)==0)
                   sailing_explore(info);
                else sailing_to_fish(1,info);
            }
            //清空数组(无人死亡)
            static bool boat_land1=true;
            static bool m=true;
            static bool k1=true,k2=true,k3=true;
            if(Boat_farmer.size()==5)
            {
                if(on_E_land_farmer.size()>=5&&on_E_land_farmer.size()<10&&k1)
                {
                    Boat_farmer.clear();
                    k1=false;
                }
                if(on_E_land_farmer.size()>=10&&on_E_land_farmer.size()<15&&k2)
                {
                    Boat_farmer.clear();
                    k2=false;
                    boat_land1=true;
                    m=true;
                }
                if(on_E_land_farmer.size()>=15&&k3)
                {
                    Boat_farmer.clear();
                    k3=false;
                }
            }
            //运输船移动到岸边
            if(Boat_farmer.size()==0&&m)
            {
                if(movingWoodBoat.size())
                {
                    switch (branch) {
                    case 1:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    case 2:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    case 3:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    default:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    }
                    m=false;
                }
                else
                {
                    switch (branch) {
                    case 1:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    case 2:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    case 3:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    default:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,wx*BLOCKSIDELENGTH,wy*BLOCKSIDELENGTH);
                        break;
                    }
                    m=false;
                }
            }
            //5个村民送至敌方大陆
            if(Boat_farmer.size()<5&&idleFarmer.size()&&farmer_on_boat(info))
            {
                if(idleWoodBoat.size())
                {
                    DebugText("Boat_Farmer:"+QString::number(Boat_farmer.size()));
                    DebugText("on_E_land_Farmer:"+QString::number(on_E_land_farmer.size()));
                    farmer_to_WoodBoat(info);
                }
                if(movingWoodBoat.size())
                {
                    if((movingWoodBoat[0].BlockDR>=wx-1)&&(movingWoodBoat[0].BlockDR<=wx+1)&&(movingWoodBoat[0].BlockUR>=wy-1)&&(movingWoodBoat[0].BlockUR<=wy+1))
                    {
                        DebugText("Boat_Farmer:"+QString::number(Boat_farmer.size()));
                        DebugText("on_E_land_Farmer:"+QString::number(on_E_land_farmer.size()));
                        farmer_to_WoodBoat(info);
                    }
                }
            }
            if(Boat_farmer.size()>=5&&farmer_on_boat(info)&&boat_land1)
            {
                if(movingWoodBoat.size())
                {
                    switch (branch) {
                    case 1:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+40,land_Y1*BLOCKSIDELENGTH+40);
                        break;
                    case 2:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+10,land_Y1*BLOCKSIDELENGTH-10);
                        break;
                    case 3:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH-10);
                        break;
                    default:
                        HumanMove(movingWoodBoat[movingWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH+10);
                        break;
                    }
                    boat_land1=false;
                }
                else
                {
                    switch (branch) {
                    case 1:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+40,land_Y1*BLOCKSIDELENGTH+40);
                        break;
                    case 2:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH+10,land_Y1*BLOCKSIDELENGTH-10);
                        break;
                    case 3:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH-10);
                        break;
                    default:
                        HumanMove(idleWoodBoat[idleWoodBoat.size()-1].SN,land_X1*BLOCKSIDELENGTH-10,land_Y1*BLOCKSIDELENGTH+10);
                        break;
                    }
                    boat_land1=false;
                }
            }
            //升级采金
            if(idleMarket.size()&&info.Meat>=BUILDING_MARKET_GOLD_UPGRADE_FOOD&&info.Wood>=BUILDING_MARKET_GOLD_UPGRADE_WOOD&&
               idleStock.size()+bornStock.size()+upgradeDefenseArcherStock.size()+upgradeDefenseInfantryStock.size()+upgradeDefenseRiderStock.size()>=2)
            {
                BuildingAction(idleMarket[idleMarket.size()-1].SN,BUILDING_MARKET_GOLD_UPGRADE);
                upgradeGoldMarket.push_back(idleMarket[idleMarket.size()-1]);
                idleMarket.pop_back();
                Gold_Level++;
            }
            //obj：村民探索部分陆地
            if(e_idleFarmer.size()&&exploringFarmer.size()==0&&
               idleScout.size()+movingScout.size()+attackingScout.size()==0)
            {
                farmer_explore(info);
            }
            //obj：采金
            //找到金矿聚集地在附近建谷仓
            static bool from=true;
            if(many_gold(info,map)&&idleStock.size()+bornStock.size()+upgradeDefenseArcherStock.size()+upgradeDefenseInfantryStock.size()+upgradeDefenseRiderStock.size()<3&&
               idleScout.size()+movingScout.size()+attackingScout.size()>0&&info.enemy_armies.size()+info.enemy_buildings.size()==0)
            {
                if(info.Wood<BUILD_STOCK_WOOD)
                    farmer_to_tree2(3,info);
                else
                {
                    DebugText("g_x:"+QString::number(g_x)+" g_y"+QString::number(g_y));
                    int x=0,y=0;
                    switch (branch) {
                    case 1:
                        if(from)
                        {
                            start_x=127,start_y=127;
                            from=false;
                        }
                        if(find_block3_3(x,y,info)&&
                           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
                           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
                        {
                            DebugText(QString::number(x)+","+QString::number(y));
                            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,x,y);
                            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                            buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                            e_idleFarmer.pop_back();
                        }
                        break;
                    case 2:
                        if(from)
                        {
                            start_x=0,start_y=0;
                            from=false;
                        }
                        if(find_block3(x,y,info)&&
                           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
                           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
                        {
                            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,x,y);
                            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                            buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                            e_idleFarmer.pop_back();
                        }
                        break;
                    case 3:
                        if(from)
                        {
                            start_x=5,start_y=120;
                            from=false;
                        }
                        if(find_block3_2(x,y,info)&&
                           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
                           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
                        {
                            DebugText(QString::number(x)+","+QString::number(y));
                            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,x,y);
                            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                            buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                            e_idleFarmer.pop_back();
                        }
                        break;
                    default:
                        if(from)
                        {
                            start_x=0,start_y=127;
                            from=false;
                        }
                        if(find_block3_2(x,y,info)&&
                           idleblock(x,y,info)&&idleblock(x+1,y,info)&&idleblock(x,y+1,info)&&idleblock(x+1,y+1,info)&&
                           idleblock(x+2,y,info)&&idleblock(x+2,y+1,info)&&idleblock(x,y+2,info)&&idleblock(x+1,y+2,info)&&idleblock(x+2,y+2,info))
                        {
                            HumanBuild(e_idleFarmer[e_idleFarmer.size()-1].SN,BUILDING_STOCK,x,y);
                            DebugText("安排村民"+QString::number(e_idleFarmer[e_idleFarmer.size()-1].SN)+"造仓库");
                            buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                            e_idleFarmer.pop_back();
                        }
                        break;
                    }
                }
            }
            if(idleScout.size()+movingScout.size()+attackingScout.size()>0&&
               e_idleFarmer.size()&&have_gold(info)&&info.enemy_armies.size()+info.enemy_buildings.size()==0)
                farmer_to_gold(10,info);
            if(idleStock.size()+bornStock.size()+upgradeDefenseArcherStock.size()+upgradeDefenseInfantryStock.size()+upgradeDefenseRiderStock.size()>2&&
              many_gold(info,map)&&e_idleFarmer.size()&&info.enemy_armies.size()+info.enemy_buildings.size()==0)
                farmer_to_gold(15,info);
            //obj：在岸边建造仓库
            if(idleStock.size()+upgradeDefenseArcherStock.size()+upgradeDefenseInfantryStock.size()+upgradeDefenseRiderStock.size()+bornStock.size()<2&&
               e_idleFarmer.size()&&info.Wood>=BUILD_STOCK_WOOD)
                farmer_to_stock(info);
            if(bornStock.size()&&e_idleFarmer.size()&&buildingStockFarmer.size()<3)
            {
                HumanAction(e_idleFarmer[e_idleFarmer.size()-1].SN,bornStock[bornStock.size()-1].SN);
                buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                e_idleFarmer.pop_back();
            }
            if(idleStock.size()+upgradeDefenseArcherStock.size()+upgradeDefenseInfantryStock.size()+upgradeDefenseRiderStock.size()+bornStock.size()>1&&
               info.Wood<BUILD_STOCK_WOOD+2*BUILD_ARMYCAMP_WOOD)
            //obj：建造2个兵营
            if(idleStock.size()+upgradeDefenseArcherStock.size()+upgradeDefenseInfantryStock.size()+upgradeDefenseRiderStock.size()+bornStock.size()>1&&
               e_idleFarmer.size()&&idleArmycamp.size()+bornArmycamp.size()+upgradeClubmanArmycamp.size()+createClubmanArmycamp.size()+createSlingerArmycamp.size()<2)
            {
                if(info.Wood<BUILD_ARMYCAMP_WOOD)
                    farmer_to_tree2(3,info);
                else farmer_to_armycamp(info);
            }
            if(bornArmycamp.size()&&e_idleFarmer.size()&&buildingArmycampFarmer.size()<3)
            {
                HumanAction(e_idleFarmer[e_idleFarmer.size()-1].SN,bornArmycamp[bornArmycamp.size()-1].SN);
                buildingStockFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                e_idleFarmer.pop_back();
            }
            //obj：建造马厩
            if(idleArmycamp.size()+upgradeClubmanArmycamp.size()+createClubmanArmycamp.size()+createSlingerArmycamp.size()>1&&
               e_idleFarmer.size()&&idleStable.size()+createScoutStable.size()+bornStable.size()==0)
            {
                if(info.Wood<BUILD_STABLE_WOOD)
                    farmer_to_tree2(3,info);
                else farmer_to_stable(info);
            }
            if(bornStable.size()&&e_idleFarmer.size()&&buildingStableFarmer.size()<3)
            {
                HumanAction(e_idleFarmer[e_idleFarmer.size()-1].SN,bornStable[bornStable.size()-1].SN);
                buildingStableFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                e_idleFarmer.pop_back();
            }
            //obj：建造靶场
            if(idleArmycamp.size()+upgradeClubmanArmycamp.size()+createClubmanArmycamp.size()+createSlingerArmycamp.size()>=2&&
               e_idleFarmer.size()&&idleStable.size()+bornStable.size()+createScoutStable.size()>0&&
               idleRange.size()+bornRange.size()+createBowmanRange.size()==0)
            {
                if(info.Wood<BUILD_RANGE_WOOD)
                    farmer_to_tree2(3,info);
                else farmer_to_range(info);
            }
            if(bornRange.size()&&e_idleFarmer.size()&&buildingRangeFarmer.size()<3)
            {
                HumanAction(e_idleFarmer[e_idleFarmer.size()-1].SN,bornRange[bornRange.size()-1].SN);
                buildingRangeFarmer.push_back(e_idleFarmer[e_idleFarmer.size()-1]);
                e_idleFarmer.pop_back();
            }
            //obj：兵营1升级建造斧头兵
            static bool upArmycamp=true;
            static int upnum=0;
            static tagBuilding Armycamp1;
            if(idleArmycamp.size()+upgradeClubmanArmycamp.size()+createClubmanArmycamp.size()+createSlingerArmycamp.size()>=1&&
               info.Meat>=BUILDING_ARMYCAMP_UPGRADE_CLUBMAN_FOOD&&idleArmycamp.size()&&upArmycamp&&idleScout.size()+movingScout.size()+attackingScout.size()>0)
            {
                BuildingAction(idleArmycamp[idleArmycamp.size()-1].SN,BUILDING_ARMYCAMP_UPGRADE_CLUBMAN);
                upArmycamp=false;
                upnum=idleArmycamp[idleArmycamp.size()-1].SN;
                Armycamp1=idleArmycamp[idleArmycamp.size()-1];
            }
            if(upnum!=0&&upgradeClubmanArmycamp.size()==0&&info.Meat>=BUILDING_ARMYCAMP_CREATE_CLUBMAN_FOOD&&
               Armycamp1.Project!=BUILDING_ARMYCAMP_CREATE_CLUBMAN&&
               idleSwordsman.size()+movingSwordsman.size()+attackingSwordsman.size()+createClubmanArmycamp.size()<5)
            {
                BuildingAction(upnum,BUILDING_ARMYCAMP_CREATE_CLUBMAN);
                createClubmanArmycamp.push_back(Armycamp1);
                if(idleArmycamp.size()==2)
                {
                    if(idleArmycamp[0].SN==upnum)
                    {
                        idleArmycamp[0]=idleArmycamp[1];
                        idleArmycamp.pop_back();
                    }
                    else idleArmycamp.pop_back();
                }
                else idleArmycamp.pop_back();
            }
            //obj：兵营2建造投石兵
            if(idleArmycamp.size()+upgradeClubmanArmycamp.size()+createClubmanArmycamp.size()+createSlingerArmycamp.size()>=2&&
               info.Meat>=BUILDING_ARMYCAMP_CREATE_SLINGER_FOOD&&info.Stone>=BUILDING_ARMYCAMP_CREATE_SLINGER_STONE&&
               idleSlinger.size()+movingSlinger.size()+attackingSlinger.size()+createSlingerArmycamp.size()<5&&upArmycamp&&idleScout.size()+movingScout.size()+attackingScout.size()>0)
            {
                for(int i=0;i<idleArmycamp.size();i++)
                {
                    if(idleArmycamp[i].SN!=upnum)
                    {
                        BuildingAction(idleArmycamp[i].SN,BUILDING_ARMYCAMP_CREATE_SLINGER);
                        createSlingerArmycamp.push_back(idleArmycamp[i]);
                        if(idleArmycamp.size()==2)
                        {
                            if(idleArmycamp[0].SN!=upnum)
                            {
                                idleArmycamp[0]=idleArmycamp[1];
                                idleArmycamp.pop_back();
                            }
                            else idleArmycamp.pop_back();
                        }
                        else idleArmycamp.pop_back();
                        break;
                    }
                }
            }
            //obj：马厩生产骑兵（优先）
            if(idleArmycamp.size()+upgradeClubmanArmycamp.size()+createClubmanArmycamp.size()+createSlingerArmycamp.size()>=1&&
               info.Meat>=BUILDING_STABLE_CREATE_SCOUT_FOOD&&idleStable.size()&&
               idleScout.size()+movingScout.size()+attackingScout.size()+createScoutStable.size()<5)
            {
                BuildingAction(idleStable[idleStable.size()-1].SN,BUILDING_STABLE_CREATE_SCOUT);
                createScoutStable.push_back(idleStable[idleStable.size()-1]);
                idleStable.pop_back();
            }
            //obj：靶场生产弓兵
            if(idleRange.size()+createBowmanRange.size()>=1&&
               info.Meat>=BUILDING_RANGE_CREATE_BOWMAN_FOOD&&idleRange.size()&&
               idleBowman.size()+movingBowman.size()+attackingBowman.size()+createBowmanRange.size()<5)
            {
                if(info.Wood<BUILDING_RANGE_CREATE_BOWMAN_WOOD)
                    farmer_to_tree2(3,info);
                BuildingAction(idleRange[idleRange.size()-1].SN,BUILDING_RANGE_CREATE_BOWMAN);
                createBowmanRange.push_back(idleRange[idleRange.size()-1]);
                idleRange.pop_back();
            }
            //obj：骑兵寻找敌军
            if(idleScout.size()&&movingScout.size()<2&&idleScout.size()+movingScout.size()+attackingScout.size()<2&&
               idleScout.size()+movingScout.size()+attackingScout.size()+
               idleclubman.size()+movingclubman.size()+attackingclubman.size()+
               idleSwordsman.size()+movingSwordsman.size()+attackingSwordsman.size()+
               idleSlinger.size()+movingSlinger.size()+attackingSlinger.size()+
               idleBowman.size()+movingBowman.size()+attackingBowman.size()>=15)
                scout_explore(info);
            if(idleScout.size()&&movingScout.size()<2&&idleScout.size()+movingScout.size()+attackingScout.size()>=2&&
               idleScout.size()+movingScout.size()+attackingScout.size()+
               idleclubman.size()+movingclubman.size()+attackingclubman.size()+
               idleSwordsman.size()+movingSwordsman.size()+attackingSwordsman.size()+
               idleSlinger.size()+movingSlinger.size()+attackingSlinger.size()+
               idleBowman.size()+movingBowman.size()+attackingBowman.size()>=15)
                scout_explore2(info);
            //obj：战略部署
            if(idleShip.size())
                is_enemy_ship(info);
            decide_enemy_block(info);
            static bool buildflag=true;
            if(e_idleFarmer.size()&&info.Stone>=BUILD_ARROWTOWER_STONE&&idleStable.size()+bornStable.size()+createScoutStable.size()>0&&buildflag)
            {
                farmer_to_arrowtower(info);
                buildflag=false;
            }
            break;
    }
    //清空管理系统
    idleFarmer.clear();
    cuttingFarmer.clear();
    fishingFarmer.clear();
    huntingELFarmer.clear();
    huntingGZFarmer.clear();
    miningFarmer.clear();
    goldFarmer.clear();
    idlesailingBoat.clear();
    fishingsailingBoat.clear();
    buildingDockFarmer.clear();
    buildingCenterFarmer.clear();
    buildingFarmFarmer.clear();
    buildingMarketFarmer.clear();
    buildingGranaryFarmer.clear();
    on_E_land_farmer.clear();
    e_idleFarmer.clear();
    exploringFarmer.clear();
    e_cuttingFarmer.clear();
    e_miningFarmer.clear();
    buildingStockFarmer.clear();
    buildingArmycampFarmer.clear();
    buildingStableFarmer.clear();
    buildingRangeFarmer.clear();
    buildingArrowtowerFarmer.clear();
    idleHome.clear();
    bornHome.clear();
    idleCenter.clear();
    bornCenter.clear();
    createHumanCenter.clear();
    upgradeCenter.clear();
    idleDock.clear();
    createSailingDock.clear();
    createWoodBoatDock.clear();
    createShipDock.clear();
    bornDock.clear();
    idlesailingBoat.clear();
    fishingsailingBoat.clear();
    idleGranary.clear();
    arrowtowerGranary.clear();
    bornGranary.clear();
    idleMarket.clear();
    bornMarket.clear();
    upgradeWoodMarket.clear();
    upgradeStoneMarket.clear();
    upgradeGoldMarket.clear();
    upgradeFarmMarket.clear();
    idleFarm.clear();
    bornFarm.clear();
    idleShip.clear();
    exploringShip.clear();
    attackingShip.clear();
    idleWoodBoat.clear();
    movingWoodBoat.clear();
    idleStock.clear();
    bornStock.clear();
    upgradeToolStock.clear();
    upgradeDefenseInfantryStock.clear();
    upgradeDefenseArcherStock.clear();
    upgradeDefenseRiderStock.clear();
    //军队
    idleArmycamp.clear();
    bornArmycamp.clear();
    createClubmanArmycamp.clear();
    createSlingerArmycamp.clear();
    upgradeClubmanArmycamp.clear();
    idleRange.clear();
    bornRange.clear();
    createBowmanRange.clear();
    idleStable.clear();
    bornStable.clear();
    createScoutStable.clear();
    idleArrowtower.clear();
    bornArrowtower.clear();
    attackingArrowtower.clear();
    //士兵
    idleSlinger.clear();
    movingSlinger.clear();
    attackingSlinger.clear();
    idleSwordsman.clear();
    movingSwordsman.clear();
    attackingSwordsman.clear();
    idleBowman.clear();
    movingBowman.clear();
    attackingBowman.clear();
    idleScout.clear();
    movingScout.clear();
    attackingScout.clear();
    idleclubman.clear();
    movingclubman.clear();
    attackingclubman.clear();
    return;
}
